GY-63_MS5611/libraries/AD524X/AD524X.h

89 lines
1.9 KiB
C
Raw Normal View History

2020-11-27 05:10:47 -05:00
#pragma once
//
// FILE: AD524X.h
// AUTHOR: Rob Tillaart
2022-10-25 11:57:23 -04:00
// VERSION: 0.3.5
// PURPOSE: I2C digital PotentioMeter AD5241 AD5242
// DATE: 2013-10-12
2020-11-27 05:10:47 -05:00
// URL: https://github.com/RobTillaart/AD524X
//
#include "Arduino.h"
2020-11-27 05:10:47 -05:00
#include "Wire.h"
2022-10-25 11:57:23 -04:00
#define AD524X_LIB_VERSION (F("0.3.5"))
2021-01-29 06:31:58 -05:00
2021-12-10 08:52:27 -05:00
#define AD524X_OK 0
#define AD524X_ERROR 100
2021-01-29 06:31:58 -05:00
class AD524X
{
public:
2021-01-29 06:31:58 -05: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 13:31:52 -04:00
2022-10-25 11:57:23 -04: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 06:31:58 -05: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 11:57:23 -04: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 06:31:58 -05:00
uint8_t getO1();
uint8_t getO2();
uint8_t midScaleReset(const uint8_t rdac);
uint8_t pmCount() { return _pmCount; };
2022-10-25 11:57:23 -04:00
// debugging
uint8_t readBackRegister(); // returns the last value written in register.
2021-01-29 06:31:58 -05:00
2022-10-25 11:57:23 -04:00
// experimental - to be tested - use at own risk
uint8_t shutDown(); // datasheet P15
2021-01-29 06:31:58 -05:00
protected:
uint8_t _pmCount = 0;
private:
2021-10-16 15:39:45 -04:00
uint8_t send(const uint8_t cmd, const uint8_t value);
2021-01-29 06:31:58 -05:00
uint8_t _address;
uint8_t _lastValue[2];
uint8_t _O1;
uint8_t _O2;
2021-01-29 06:31:58 -05:00
TwoWire* _wire;
};
2021-01-29 06:31:58 -05:00
2021-10-16 15:39:45 -04:00
//////////////////////////////////////////////////////////////
//
// DERIVED CLASSES
2022-08-13 13:31:52 -04:00
//
2021-01-29 06:31:58 -05:00
class AD5241 : public AD524X
{
public:
AD5241(const uint8_t address, TwoWire *wire = &Wire);
};
2021-10-16 15:39:45 -04:00
2021-01-29 06:31:58 -05:00
class AD5242 : public AD524X
{
public:
AD5242(const uint8_t address, TwoWire *wire = &Wire);
};
2020-11-27 05:10:47 -05:00
// -- END OF FILE --
2022-08-13 13:31:52 -04:00