mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-09-19 16:46:11 -04:00
0.4.1 AD524X
This commit is contained in:
parent
579ec66f85
commit
d118589587
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// FILE: AD524X.cpp
|
// FILE: AD524X.cpp
|
||||||
// AUTHOR: Rob Tillaart
|
// AUTHOR: Rob Tillaart
|
||||||
// VERSION: 0.4.0
|
// VERSION: 0.4.1
|
||||||
// PURPOSE: I2C digital potentiometer AD5241 AD5242
|
// PURPOSE: I2C digital potentiometer AD5241 AD5242
|
||||||
// DATE: 2013-10-12
|
// DATE: 2013-10-12
|
||||||
// URL: https://github.com/RobTillaart/AD524X
|
// URL: https://github.com/RobTillaart/AD524X
|
||||||
@ -23,7 +23,9 @@ AD524X::AD524X(const uint8_t address, TwoWire *wire)
|
|||||||
// address: 0x01011xx = 0x2C - 0x2F
|
// address: 0x01011xx = 0x2C - 0x2F
|
||||||
_address = address;
|
_address = address;
|
||||||
_wire = wire;
|
_wire = wire;
|
||||||
_lastValue[0] = _lastValue[1] = AD524X_MIDPOINT; // power on reset => mid position
|
|
||||||
|
// power on reset => mid position
|
||||||
|
_lastValue[0] = _lastValue[1] = AD524X_MIDPOINT;
|
||||||
_O1 = _O2 = 0;
|
_O1 = _O2 = 0;
|
||||||
_pmCount = 2;
|
_pmCount = 2;
|
||||||
}
|
}
|
||||||
@ -81,7 +83,7 @@ uint8_t AD524X::write(const uint8_t rdac, const uint8_t value)
|
|||||||
if (rdac >= _pmCount) return AD524X_ERROR;
|
if (rdac >= _pmCount) return AD524X_ERROR;
|
||||||
|
|
||||||
uint8_t cmd = (rdac == 0) ? AD524X_RDAC0 : AD524X_RDAC1;
|
uint8_t cmd = (rdac == 0) ? AD524X_RDAC0 : AD524X_RDAC1;
|
||||||
// apply the output lines
|
// apply the output lines
|
||||||
cmd = cmd | _O1 | _O2;
|
cmd = cmd | _O1 | _O2;
|
||||||
_lastValue[rdac] = value;
|
_lastValue[rdac] = value;
|
||||||
return send(cmd, value);
|
return send(cmd, value);
|
||||||
@ -92,10 +94,11 @@ uint8_t AD524X::write(const uint8_t rdac, const uint8_t value, const uint8_t O1,
|
|||||||
{
|
{
|
||||||
if (rdac >= _pmCount) return AD524X_ERROR;
|
if (rdac >= _pmCount) return AD524X_ERROR;
|
||||||
|
|
||||||
uint8_t cmd = (rdac == 0) ? AD524X_RDAC0 : AD524X_RDAC1;
|
|
||||||
_O1 = (O1 == LOW) ? 0 : AD524X_O1_HIGH;
|
_O1 = (O1 == LOW) ? 0 : AD524X_O1_HIGH;
|
||||||
_O2 = (O2 == LOW) ? 0 : AD524X_O2_HIGH;
|
_O2 = (O2 == LOW) ? 0 : AD524X_O2_HIGH;
|
||||||
// apply the output lines
|
|
||||||
|
uint8_t cmd = (rdac == 0) ? AD524X_RDAC0 : AD524X_RDAC1;
|
||||||
|
// apply the output lines
|
||||||
cmd = cmd | _O1 | _O2;
|
cmd = cmd | _O1 | _O2;
|
||||||
_lastValue[rdac] = value;
|
_lastValue[rdac] = value;
|
||||||
return send(cmd, value);
|
return send(cmd, value);
|
||||||
@ -168,7 +171,7 @@ uint8_t AD524X::shutDown()
|
|||||||
uint8_t AD524X::pmCount()
|
uint8_t AD524X::pmCount()
|
||||||
{
|
{
|
||||||
return _pmCount;
|
return _pmCount;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////
|
||||||
@ -191,13 +194,46 @@ uint8_t AD524X::send(const uint8_t cmd, const uint8_t value)
|
|||||||
AD5241::AD5241(const uint8_t address, TwoWire *wire) : AD524X(address, wire)
|
AD5241::AD5241(const uint8_t address, TwoWire *wire) : AD524X(address, wire)
|
||||||
{
|
{
|
||||||
_pmCount = 1;
|
_pmCount = 1;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t AD5241::write(const uint8_t value)
|
||||||
|
{
|
||||||
|
// apply the output lines
|
||||||
|
uint8_t cmd = AD524X_RDAC0 | _O1 | _O2;
|
||||||
|
_lastValue[0] = value;
|
||||||
|
return send(cmd, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t AD5241::write(const uint8_t value, const uint8_t O1, const uint8_t O2)
|
||||||
|
{
|
||||||
|
_O1 = (O1 == LOW) ? 0 : AD524X_O1_HIGH;
|
||||||
|
_O2 = (O2 == LOW) ? 0 : AD524X_O2_HIGH;
|
||||||
|
|
||||||
|
// apply the output lines
|
||||||
|
uint8_t cmd = AD524X_RDAC0 | _O1 | _O2;
|
||||||
|
_lastValue[0] = value;
|
||||||
|
return send(cmd, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t AD5241::write(const uint8_t rdac, const uint8_t value)
|
||||||
|
{
|
||||||
|
return AD524X::write(rdac, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t AD5241::write(const uint8_t rdac, const uint8_t value, const uint8_t O1, const uint8_t O2)
|
||||||
|
{
|
||||||
|
return AD524X::write(rdac, value, O1, O2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
AD5242::AD5242(const uint8_t address, TwoWire *wire) : AD524X(address, wire)
|
AD5242::AD5242(const uint8_t address, TwoWire *wire) : AD524X(address, wire)
|
||||||
{
|
{
|
||||||
_pmCount = 2;
|
_pmCount = 2;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
// -- END OF FILE --
|
// -- END OF FILE --
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
//
|
//
|
||||||
// FILE: AD524X.h
|
// FILE: AD524X.h
|
||||||
// AUTHOR: Rob Tillaart
|
// AUTHOR: Rob Tillaart
|
||||||
// VERSION: 0.4.0
|
// VERSION: 0.4.1
|
||||||
// PURPOSE: I2C digital PotentioMeter AD5241 AD5242
|
// PURPOSE: I2C digital PotentioMeter AD5241 AD5242
|
||||||
// DATE: 2013-10-12
|
// DATE: 2013-10-12
|
||||||
// URL: https://github.com/RobTillaart/AD524X
|
// URL: https://github.com/RobTillaart/AD524X
|
||||||
@ -12,7 +12,7 @@
|
|||||||
#include "Wire.h"
|
#include "Wire.h"
|
||||||
|
|
||||||
|
|
||||||
#define AD524X_LIB_VERSION (F("0.4.0"))
|
#define AD524X_LIB_VERSION (F("0.4.1"))
|
||||||
|
|
||||||
|
|
||||||
#define AD524X_OK 0
|
#define AD524X_OK 0
|
||||||
@ -25,7 +25,7 @@
|
|||||||
class AD524X
|
class AD524X
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit AD524X(const uint8_t address, TwoWire *wire = &Wire);
|
AD524X(const uint8_t address, TwoWire *wire = &Wire);
|
||||||
|
|
||||||
#if defined (ESP8266) || defined(ESP32)
|
#if defined (ESP8266) || defined(ESP32)
|
||||||
bool begin(uint8_t sda, uint8_t scl);
|
bool begin(uint8_t sda, uint8_t scl);
|
||||||
@ -82,6 +82,12 @@ class AD5241 : public AD524X
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AD5241(const uint8_t address, TwoWire *wire = &Wire);
|
AD5241(const uint8_t address, TwoWire *wire = &Wire);
|
||||||
|
|
||||||
|
uint8_t write(const uint8_t value);
|
||||||
|
uint8_t write(const uint8_t value, const uint8_t O1, const uint8_t O2);
|
||||||
|
|
||||||
|
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);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,10 +6,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
|||||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
|
|
||||||
|
## [0.4.1] - 2023-02-26
|
||||||
|
- fix #17 support **AD5241::write()**
|
||||||
|
- update readme.md
|
||||||
|
|
||||||
|
|
||||||
## [0.4.0] - 2023-02-03
|
## [0.4.0] - 2023-02-03
|
||||||
- fix #18 support Wire2 (RP2040 etc)
|
- fix #18 support Wire2 (RP2040 etc)
|
||||||
|
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
## [0.3.6] - 2023-01-11
|
## [0.3.6] - 2023-01-11
|
||||||
|
@ -48,6 +48,10 @@ The AD524X has two address lines to configure the I2C address. 0x2C - 0x2F
|
|||||||
|
|
||||||
## Interface
|
## Interface
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
#include "AD524X.h"
|
||||||
|
```
|
||||||
|
|
||||||
The library has a number of functions which are all quite straightforward.
|
The library has a number of functions which are all quite straightforward.
|
||||||
One can get / set the value of (both) the potentiometer(s), and the O1 and O2 output lines.
|
One can get / set the value of (both) the potentiometer(s), and the O1 and O2 output lines.
|
||||||
|
|
||||||
@ -88,11 +92,21 @@ The developer is responsible for handling this correctly.
|
|||||||
- **uint8_t readBackRegister()** read register back, for debugging.
|
- **uint8_t readBackRegister()** read register back, for debugging.
|
||||||
|
|
||||||
|
|
||||||
### Experimental
|
#### Experimental
|
||||||
|
|
||||||
- **uint8_t shutDown()** check datasheet, not tested yet, use at own risk.
|
- **uint8_t shutDown()** check datasheet, not tested yet, use at own risk.
|
||||||
|
|
||||||
|
|
||||||
|
## Interface AD5421 specific
|
||||||
|
|
||||||
|
Since 0.4.1 the library supports writing explicit to port 0
|
||||||
|
as that is the only port.
|
||||||
|
|
||||||
|
- **uint8_t write(const uint8_t value)** set rdac 0 to value 0..255.
|
||||||
|
- **uint8_t write(const uint8_t value, const uint8_t O1, const uint8_t O2)**
|
||||||
|
idem + set output lines O1 and O2 too.
|
||||||
|
|
||||||
|
|
||||||
## Operation
|
## Operation
|
||||||
|
|
||||||
The examples show the basic working of the functions.
|
The examples show the basic working of the functions.
|
||||||
@ -118,8 +132,6 @@ The examples show the basic working of the functions.
|
|||||||
|
|
||||||
#### Could
|
#### Could
|
||||||
|
|
||||||
- consider adding write(value) with default PM == 0 ? (wrapper)
|
|
||||||
- see issue #16 / #17
|
|
||||||
|
|
||||||
#### Wont
|
#### Wont
|
||||||
|
|
||||||
|
@ -49,5 +49,5 @@ void loop()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// -- END OF FILE --
|
// -- END OF FILE --
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/RobTillaart/AD524X"
|
"url": "https://github.com/RobTillaart/AD524X"
|
||||||
},
|
},
|
||||||
"version": "0.4.0",
|
"version": "0.4.1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"frameworks": "arduino",
|
"frameworks": "arduino",
|
||||||
"platforms": "*",
|
"platforms": "*",
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name=AD524X
|
name=AD524X
|
||||||
version=0.4.0
|
version=0.4.1
|
||||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||||
sentence=Arduino Library for AD524X
|
sentence=Arduino Library for AD524X
|
||||||
|
@ -40,7 +40,7 @@ unittest(test_constructors)
|
|||||||
{
|
{
|
||||||
Wire.begin();
|
Wire.begin();
|
||||||
|
|
||||||
AD524X ADx(0x2C); // AD0 & AD1 == GND
|
AD524X ADx(0x2C); // AD0 & AD1 == GND
|
||||||
assertEqual(127, ADx.read(0));
|
assertEqual(127, ADx.read(0));
|
||||||
assertEqual(127, ADx.read(1));
|
assertEqual(127, ADx.read(1));
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ unittest(test_constructors)
|
|||||||
|
|
||||||
unittest(test_reset)
|
unittest(test_reset)
|
||||||
{
|
{
|
||||||
AD524X AD(0x2C); // AD0 & AD1 == GND
|
AD524X AD(0x2C); // AD0 & AD1 == GND
|
||||||
Wire.begin();
|
Wire.begin();
|
||||||
|
|
||||||
assertEqual(127, AD.read(0));
|
assertEqual(127, AD.read(0));
|
||||||
@ -83,7 +83,7 @@ unittest(test_reset)
|
|||||||
|
|
||||||
unittest(test_write_read)
|
unittest(test_write_read)
|
||||||
{
|
{
|
||||||
AD524X AD(0x2C); // AD0 & AD1 == GND
|
AD524X AD(0x2C); // AD0 & AD1 == GND
|
||||||
Wire.begin();
|
Wire.begin();
|
||||||
|
|
||||||
assertEqual(127, AD.read(0));
|
assertEqual(127, AD.read(0));
|
||||||
@ -101,7 +101,7 @@ unittest(test_write_read)
|
|||||||
|
|
||||||
unittest(test_O1_O2)
|
unittest(test_O1_O2)
|
||||||
{
|
{
|
||||||
AD524X AD(0x2C); // AD0 & AD1 == GND
|
AD524X AD(0x2C); // AD0 & AD1 == GND
|
||||||
Wire.begin();
|
Wire.begin();
|
||||||
|
|
||||||
assertEqual(0, AD.getO1());
|
assertEqual(0, AD.getO1());
|
||||||
|
Loading…
Reference in New Issue
Block a user