2022-02-14 14:53:03 -05:00
|
|
|
#pragma once
|
|
|
|
//
|
|
|
|
// FILE: X9C10X.h
|
|
|
|
// AUTHOR: Rob Tillaart
|
2022-11-27 05:27:05 -05:00
|
|
|
// VERSION: 0.2.2
|
2022-02-14 14:53:03 -05:00
|
|
|
// PURPOSE: Arduino Library for X9C10X series digital potentiometer.
|
2022-02-23 09:57:01 -05:00
|
|
|
// URL: https://github.com/RobTillaart/X9C10X
|
2022-02-14 14:53:03 -05:00
|
|
|
|
|
|
|
|
|
|
|
#include "Arduino.h"
|
|
|
|
|
2022-11-27 05:27:05 -05:00
|
|
|
#define X9C10X_LIB_VERSION (F("0.2.2"))
|
2022-02-14 14:53:03 -05:00
|
|
|
|
|
|
|
|
2022-07-15 06:26:27 -04:00
|
|
|
/////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// X9C MINIMAL BASE CLASS
|
|
|
|
//
|
|
|
|
class X9C
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
X9C();
|
|
|
|
|
|
|
|
void begin(uint8_t pulsePin, uint8_t directionPin, uint8_t selectPin);
|
|
|
|
|
|
|
|
// step size 1.
|
2022-07-24 10:36:28 -04:00
|
|
|
// return false if end of range reached.
|
2022-07-15 06:26:27 -04:00
|
|
|
bool incr();
|
|
|
|
bool decr();
|
|
|
|
|
|
|
|
// use with care
|
|
|
|
void store();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
uint8_t _pulsePin;
|
|
|
|
uint8_t _directionPin;
|
|
|
|
uint8_t _selectPin;
|
|
|
|
|
|
|
|
void _move(uint8_t direction, uint8_t steps = 1);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// X9C10X BASE CLASS
|
|
|
|
//
|
|
|
|
class X9C10X : public X9C
|
2022-02-14 14:53:03 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// ohm can be actual measured value e.g 9950 ohm (calibration)
|
2022-02-16 14:14:45 -05:00
|
|
|
X9C10X(uint32_t maxOhm = 10000);
|
2022-02-14 14:53:03 -05:00
|
|
|
|
|
|
|
// position = 0..99
|
2022-07-24 10:36:28 -04:00
|
|
|
// values > 99 are truncated.
|
2022-02-23 09:57:01 -05:00
|
|
|
// forced = true will ignore the cached position
|
2022-07-24 10:36:28 -04:00
|
|
|
// takes up to 150 steps as one cannot read the position from device.
|
2022-02-23 09:57:01 -05:00
|
|
|
// forced = default false as that is safer and backwards compatible.
|
2022-07-24 10:36:28 -04:00
|
|
|
// returns new position 0..99
|
|
|
|
uint8_t setPosition(uint8_t position, bool forced = false);
|
2022-11-27 05:27:05 -05:00
|
|
|
uint8_t getPosition();
|
2022-02-14 14:53:03 -05:00
|
|
|
|
|
|
|
// step size 1.
|
2022-07-24 10:36:28 -04:00
|
|
|
// return false if end of range reached.
|
2022-02-23 09:57:01 -05:00
|
|
|
bool incr();
|
|
|
|
bool decr();
|
2022-02-14 14:53:03 -05:00
|
|
|
|
|
|
|
// use with care
|
2022-07-24 10:36:28 -04:00
|
|
|
// returns new position 0..99
|
2022-02-14 14:53:03 -05:00
|
|
|
uint8_t store();
|
2022-07-24 10:36:28 -04:00
|
|
|
// note: restoreInternalPosition() is not available in X9C base class.
|
|
|
|
// position = 0..99
|
|
|
|
// values > 99 are truncated.
|
|
|
|
// returns new position 0..99
|
2022-11-27 05:27:05 -05:00
|
|
|
uint8_t restoreInternalPosition(uint8_t position);
|
2022-02-14 14:53:03 -05:00
|
|
|
|
|
|
|
// current resistance in ohm.
|
2022-07-15 06:26:27 -04:00
|
|
|
uint32_t getOhm();
|
|
|
|
uint32_t getMaxOhm();
|
|
|
|
uint8_t Ohm2Position(uint32_t value, bool invert = false);
|
2022-02-14 14:53:03 -05:00
|
|
|
|
2022-07-15 06:26:27 -04:00
|
|
|
// returns 0 as it is unknown for X9C10X
|
|
|
|
uint16_t getType();
|
2022-02-14 14:53:03 -05:00
|
|
|
|
|
|
|
|
|
|
|
protected:
|
2022-07-15 06:26:27 -04:00
|
|
|
uint32_t _maxOhm = 0;
|
|
|
|
uint8_t _position = 0;
|
|
|
|
uint16_t _type = 0;
|
2022-02-14 14:53:03 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////
|
|
|
|
//
|
2022-07-15 06:26:27 -04:00
|
|
|
// SPECIFIC DERIVED DEVICE CLASSES
|
2022-02-14 14:53:03 -05:00
|
|
|
//
|
|
|
|
class X9C102 : public X9C10X
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
X9C102(uint32_t ohm = 1000);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class X9C103 : public X9C10X
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
X9C103(uint32_t ohm = 10000);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class X9C104 : public X9C10X
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
X9C104(uint32_t ohm = 100000);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class X9C503 : public X9C10X
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
X9C503(uint32_t ohm = 50000);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-11-27 05:27:05 -05:00
|
|
|
// -- END OF FILE --
|
2022-02-14 14:53:03 -05:00
|
|
|
|