89 lines
1.9 KiB
C
Raw Normal View History

2020-11-27 11:10:47 +01:00
#pragma once
//
// FILE: AD524X.h
// AUTHOR: Rob Tillaart
2022-10-25 17:57:23 +02:00
// VERSION: 0.3.5
// PURPOSE: I2C digital PotentioMeter AD5241 AD5242
// DATE: 2013-10-12
2020-11-27 11:10:47 +01:00
// URL: https://github.com/RobTillaart/AD524X
//
#include "Arduino.h"
2020-11-27 11:10:47 +01:00
#include "Wire.h"
2022-10-25 17:57:23 +02:00
#define AD524X_LIB_VERSION (F("0.3.5"))
2021-01-29 12:31:58 +01:00
2021-12-10 14:52:27 +01:00
#define AD524X_OK 0
#define AD524X_ERROR 100
2021-01-29 12:31:58 +01:00
class AD524X
{
public:
2021-01-29 12:31:58 +01:00
explicit AD524X(const uint8_t address, TwoWire *wire = &Wire);
#if defined (ESP8266) || defined(ESP32)
bool begin(uint8_t sda, uint8_t scl);
#endif
bool begin();
bool isConnected();
2022-08-13 19:31:52 +02:00
2022-10-25 17:57:23 +02:00
uint8_t reset(); // reset both channels to 127 and O1/O2 to LOW
uint8_t zeroAll(); // set both channels to 0 and O1/O2 to LOW
2021-01-29 12:31:58 +01:00
uint8_t read(const uint8_t rdac);
uint8_t write(const uint8_t rdac, const uint8_t value);
uint8_t write(const uint8_t rdac, const uint8_t value, const uint8_t O1, const uint8_t O2);
2022-10-25 17:57:23 +02:00
uint8_t setO1(const uint8_t value = HIGH); // HIGH (default) / LOW
uint8_t setO2(const uint8_t value = HIGH); // HIGH (default) / LOW
2021-01-29 12:31:58 +01:00
uint8_t getO1();
uint8_t getO2();
uint8_t midScaleReset(const uint8_t rdac);
uint8_t pmCount() { return _pmCount; };
2022-10-25 17:57:23 +02:00
// debugging
uint8_t readBackRegister(); // returns the last value written in register.
2021-01-29 12:31:58 +01:00
2022-10-25 17:57:23 +02:00
// experimental - to be tested - use at own risk
uint8_t shutDown(); // datasheet P15
2021-01-29 12:31:58 +01:00
protected:
uint8_t _pmCount = 0;
private:
2021-10-16 21:39:45 +02:00
uint8_t send(const uint8_t cmd, const uint8_t value);
2021-01-29 12:31:58 +01:00
uint8_t _address;
uint8_t _lastValue[2];
uint8_t _O1;
uint8_t _O2;
2021-01-29 12:31:58 +01:00
TwoWire* _wire;
};
2021-01-29 12:31:58 +01:00
2021-10-16 21:39:45 +02:00
//////////////////////////////////////////////////////////////
//
// DERIVED CLASSES
2022-08-13 19:31:52 +02:00
//
2021-01-29 12:31:58 +01:00
class AD5241 : public AD524X
{
public:
AD5241(const uint8_t address, TwoWire *wire = &Wire);
};
2021-10-16 21:39:45 +02:00
2021-01-29 12:31:58 +01:00
class AD5242 : public AD524X
{
public:
AD5242(const uint8_t address, TwoWire *wire = &Wire);
};
2020-11-27 11:10:47 +01:00
// -- END OF FILE --
2022-08-13 19:31:52 +02:00