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
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.4.0
|
||||
// VERSION: 0.4.1
|
||||
// PURPOSE: I2C digital potentiometer AD5241 AD5242
|
||||
// DATE: 2013-10-12
|
||||
// URL: https://github.com/RobTillaart/AD524X
|
||||
@ -23,7 +23,9 @@ AD524X::AD524X(const uint8_t address, TwoWire *wire)
|
||||
// address: 0x01011xx = 0x2C - 0x2F
|
||||
_address = address;
|
||||
_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;
|
||||
_pmCount = 2;
|
||||
}
|
||||
@ -81,7 +83,7 @@ uint8_t AD524X::write(const uint8_t rdac, const uint8_t value)
|
||||
if (rdac >= _pmCount) return AD524X_ERROR;
|
||||
|
||||
uint8_t cmd = (rdac == 0) ? AD524X_RDAC0 : AD524X_RDAC1;
|
||||
// apply the output lines
|
||||
// apply the output lines
|
||||
cmd = cmd | _O1 | _O2;
|
||||
_lastValue[rdac] = 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;
|
||||
|
||||
uint8_t cmd = (rdac == 0) ? AD524X_RDAC0 : AD524X_RDAC1;
|
||||
_O1 = (O1 == LOW) ? 0 : AD524X_O1_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;
|
||||
_lastValue[rdac] = value;
|
||||
return send(cmd, value);
|
||||
@ -168,7 +171,7 @@ uint8_t AD524X::shutDown()
|
||||
uint8_t AD524X::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)
|
||||
{
|
||||
_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)
|
||||
{
|
||||
_pmCount = 2;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: AD524X.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.4.0
|
||||
// VERSION: 0.4.1
|
||||
// PURPOSE: I2C digital PotentioMeter AD5241 AD5242
|
||||
// DATE: 2013-10-12
|
||||
// URL: https://github.com/RobTillaart/AD524X
|
||||
@ -12,7 +12,7 @@
|
||||
#include "Wire.h"
|
||||
|
||||
|
||||
#define AD524X_LIB_VERSION (F("0.4.0"))
|
||||
#define AD524X_LIB_VERSION (F("0.4.1"))
|
||||
|
||||
|
||||
#define AD524X_OK 0
|
||||
@ -25,7 +25,7 @@
|
||||
class AD524X
|
||||
{
|
||||
public:
|
||||
explicit AD524X(const uint8_t address, TwoWire *wire = &Wire);
|
||||
AD524X(const uint8_t address, TwoWire *wire = &Wire);
|
||||
|
||||
#if defined (ESP8266) || defined(ESP32)
|
||||
bool begin(uint8_t sda, uint8_t scl);
|
||||
@ -82,6 +82,12 @@ class AD5241 : public AD524X
|
||||
{
|
||||
public:
|
||||
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/).
|
||||
|
||||
|
||||
## [0.4.1] - 2023-02-26
|
||||
- fix #17 support **AD5241::write()**
|
||||
- update readme.md
|
||||
|
||||
|
||||
## [0.4.0] - 2023-02-03
|
||||
- fix #18 support Wire2 (RP2040 etc)
|
||||
|
||||
|
||||
----
|
||||
|
||||
## [0.3.6] - 2023-01-11
|
||||
@ -25,14 +29,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
- add changelog.md
|
||||
- add RP2040 in build-CI
|
||||
|
||||
## [0.3.4] - 2022-08-13
|
||||
## [0.3.4] - 2022-08-13
|
||||
- fix AD524X_LIB_VERSION
|
||||
- minor edits,
|
||||
|
||||
## [0.3.3] - 2021-12-10
|
||||
- update constants, library.json, license
|
||||
|
||||
## [0.3.2] - 2021-10-16
|
||||
## [0.3.2] - 2021-10-16
|
||||
- fix build-CI, update readme.md
|
||||
|
||||
|
||||
|
@ -48,6 +48,10 @@ The AD524X has two address lines to configure the I2C address. 0x2C - 0x2F
|
||||
|
||||
## Interface
|
||||
|
||||
```cpp
|
||||
#include "AD524X.h"
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
@ -88,11 +92,21 @@ The developer is responsible for handling this correctly.
|
||||
- **uint8_t readBackRegister()** read register back, for debugging.
|
||||
|
||||
|
||||
### Experimental
|
||||
#### Experimental
|
||||
|
||||
- **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
|
||||
|
||||
The examples show the basic working of the functions.
|
||||
@ -118,8 +132,6 @@ The examples show the basic working of the functions.
|
||||
|
||||
#### Could
|
||||
|
||||
- consider adding write(value) with default PM == 0 ? (wrapper)
|
||||
- see issue #16 / #17
|
||||
|
||||
#### Wont
|
||||
|
||||
|
@ -49,5 +49,5 @@ void loop()
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/AD524X"
|
||||
},
|
||||
"version": "0.4.0",
|
||||
"version": "0.4.1",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=AD524X
|
||||
version=0.4.0
|
||||
version=0.4.1
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino Library for AD524X
|
||||
|
@ -40,7 +40,7 @@ unittest(test_constructors)
|
||||
{
|
||||
Wire.begin();
|
||||
|
||||
AD524X ADx(0x2C); // AD0 & AD1 == GND
|
||||
AD524X ADx(0x2C); // AD0 & AD1 == GND
|
||||
assertEqual(127, ADx.read(0));
|
||||
assertEqual(127, ADx.read(1));
|
||||
|
||||
@ -56,7 +56,7 @@ unittest(test_constructors)
|
||||
|
||||
unittest(test_reset)
|
||||
{
|
||||
AD524X AD(0x2C); // AD0 & AD1 == GND
|
||||
AD524X AD(0x2C); // AD0 & AD1 == GND
|
||||
Wire.begin();
|
||||
|
||||
assertEqual(127, AD.read(0));
|
||||
@ -83,7 +83,7 @@ unittest(test_reset)
|
||||
|
||||
unittest(test_write_read)
|
||||
{
|
||||
AD524X AD(0x2C); // AD0 & AD1 == GND
|
||||
AD524X AD(0x2C); // AD0 & AD1 == GND
|
||||
Wire.begin();
|
||||
|
||||
assertEqual(127, AD.read(0));
|
||||
@ -101,7 +101,7 @@ unittest(test_write_read)
|
||||
|
||||
unittest(test_O1_O2)
|
||||
{
|
||||
AD524X AD(0x2C); // AD0 & AD1 == GND
|
||||
AD524X AD(0x2C); // AD0 & AD1 == GND
|
||||
Wire.begin();
|
||||
|
||||
assertEqual(0, AD.getO1());
|
||||
|
Loading…
Reference in New Issue
Block a user