0.2.1 AD520X

This commit is contained in:
rob tillaart 2021-12-10 14:12:54 +01:00
parent b002830ff3
commit 5790442932
8 changed files with 47 additions and 25 deletions

View File

@ -2,7 +2,7 @@
// FILE: AD520X.cpp
// AUTHOR: Rob Tillaart
// DATE: 2020-07-24
// VERSION: 0.2.0
// VERSION: 0.2.1
// PURPOSE: Arduino library for AD5204 and AD5206 digital potentiometers (+ older AD8400, AD8402, AD8403)
// URL: https://github.com/RobTillaart/AD520X
//
@ -16,6 +16,8 @@
// add SetSPIspeed (generic)
// 0.2.0 2021-10-16 update build-CI
// add get- and setPercentage()
// 0.2.1 2021-12-10 update library.json, licence
// default value for setAll()
#include "AD520X.h"

View File

@ -3,7 +3,7 @@
// FILE: AD520X.h
// AUTHOR: Rob Tillaart
// DATE: 2020-07-24
// VERSION: 0.2.0
// VERSION: 0.2.1
// PURPOSE: Arduino library for AD5204 and AD5206 digital potentiometers (+ older AD8400, AD8402, AD8403)
// URL: https://github.com/RobTillaart/AD520X
//
@ -16,7 +16,9 @@
#include "SPI.h"
#define AD520X_LIB_VERSION (F("0.2.0"))
#define AD520X_LIB_VERSION (F("0.2.1"))
#define AD520X_MIDDLE_VALUE 128
class AD520X
@ -24,20 +26,20 @@ class AD520X
public:
AD520X(uint8_t select, uint8_t reset, uint8_t shutdown, uint8_t dataOut, uint8_t clock);
void begin(uint8_t value = 128);
bool setValue(uint8_t pm = 0, uint8_t value = 128);
void setAll(uint8_t value);
void begin(uint8_t value = AD520X_MIDDLE_VALUE);
bool setValue(uint8_t pm = 0, uint8_t value = AD520X_MIDDLE_VALUE);
void setAll(uint8_t value = AD520X_MIDDLE_VALUE);
uint8_t getValue(uint8_t pm = 0);
bool setPercentage(uint8_t pm = 0, float percentage = 50);
float getPercentage(uint8_t pm = 0);
void reset(uint8_t value = 128);
void reset(uint8_t value = AD520X_MIDDLE_VALUE);
uint8_t pmCount() { return _pmCount; };
void powerOn() { digitalWrite(_shutdown, LOW); };
void powerOff() { digitalWrite(_shutdown, HIGH); };
void powerDown() { powerOff(); }; // will become obsolete
void powerDown() { powerOff(); }; // obsolete, remove in 0.3.0
bool isPowerOn() { return digitalRead(_shutdown) == LOW; };
// speed in Hz

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2020-2021 Rob Tillaart
Copyright (c) 2020-2022 Rob Tillaart
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -8,14 +8,14 @@
# AD520X
Arduino library for SPI AD5204 and AD5206 digital potentiometers
Arduino library for SPI AD5204 and AD5206 digital potentiometers.
Should work for the AD840x series too (not tested).
## Description
The library is still experimental as not all functionality is tested (enough).
The library is experimental as not all functionality is tested (enough).
The **AD5204** (4 channels) and **AD5206** (6 channels) are SPI based digital potentiometers.
This library consists of a base class **AD520X** that does the work.
@ -52,19 +52,19 @@ reset and shutdown may be set to 255 too, which effectively disables them.
- **AD8402(select, reset, shutdown, dataOut = 255, clock = 255)** has 2 channels.
- **AD8403(select, reset, shutdown, dataOut = 255, clock = 255)** has 4 channels.
Note: hardware SPI is 10+ times faster on an UNO.
Note: hardware SPI is 10+ times faster on an UNO than software SPI.
### Base
Since 0.2.0 the functions have more default parameters. Potentiometer is default pot 0
and value is default the middle value of 128.
and value is default the **AD520X_MIDDLE_VALUE** of 128.
- **void begin(uint8_t value = 128)** value is the initial value of all potentiometer.
- **bool setValue(uint8_t pm = 0, uint8_t value = 128)** set a potentiometer to a value.
Default value is middle value.
Returns true if successful, false if not.
- **void setAll(uint8_t value)** set all potentiometers to the same value e.g. 0 or max or mid value.
- **void setAll(uint8_t value = 128)** set all potentiometers to the same value e.g. 0 or max or mid value.
- **uint8_t getValue(uint8_t pm = 0)** returns the last set value of a specific potentiometer.
- **void reset(uint8_t value = 128)** resets all potentiometers to value, default 128.
- **bool setPercentage(uint8_t pm = 0, float percentage = 50)** similar to setValue, percentage from 0..100%
@ -72,6 +72,9 @@ Returns true when successful, false if not.
- **float getPercentage(uint8_t pm = 0)** return the value of potentiometer pm as percentage.
The library has defined **#define AD520X_MIDDLE_VALUE 128**
### Hardware SPI
To be used only if one needs a specific speed for hardware SPI.
@ -99,10 +102,19 @@ The **selectVSPI()** or the **selectHSPI()** needs to be called BEFORE the **beg
- **uint8_t pmCount()** returns the number of internal potentiometers.
- **void powerOn()** switches the module on.
- **void powerOff()** switches the module off.
- **void powerDown()** OBSOLETE => use powerOff() instead.
- **bool isPowerOn()** returns true if on (default) or false if off.
### Obsolete
- **void powerDown()** OBSOLETE => use powerOff() instead.
## Operations
See examples.
## Future
- **void setInvert(uint8_t pm)** invert flag per potentiometer.
@ -117,9 +129,6 @@ The **selectVSPI()** or the **selectHSPI()** needs to be called BEFORE the **beg
- **void setGamma(uint8_t pm, float gamma)**
- logarithmic effect? easier with setPercentage()
- see gamma library.
- **middle value** 127 ?
- **AD520X_MIDDLE_VALUE** 127 ?
- **setSWSPIdelay()** to tune software SPI?
## Operations
See examples.

View File

@ -22,7 +22,6 @@ reset KEYWORD2
powerOn KEYWORD2
powerOff KEYWORD2
powerDown KEYWORD2
isPowerOn KEYWORD2
pmCount KEYWORD2
@ -40,3 +39,6 @@ setGPIOpins KEYWORD2
# Constants (LITERAL1)
AD520X_LIB_VERSION LITERAL1
AD520X_MIDDLE_VALUE LITERAL1

View File

@ -15,8 +15,9 @@
"type": "git",
"url": "https://github.com/RobTillaart/AD520X.git"
},
"version": "0.2.0",
"version": "0.2.1",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*"
"platforms": "*",
"headers": "AD520X.h"
}

View File

@ -1,5 +1,5 @@
name=AD520X
version=0.2.0
version=0.2.1
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for SPI AD5204 and AD5206 digital potentiometers

View File

@ -39,7 +39,7 @@ unittest_teardown()
unittest(test_begin)
{
fprintf(stderr, "AD520X_LIB_VERSION:\t%s", AD520X_LIB_VERSION);
fprintf(stderr, "AD520X_LIB_VERSION:\t%s\n", (char *) AD520X_LIB_VERSION);
AD5204 pot = AD5204(10, 12, 13); // HW SPI
pot.begin();
assertEqual(128, pot.getValue(0));
@ -67,6 +67,12 @@ unittest(test_setValue)
assertEqual(42, pot.getValue(i));
}
pot.setAll();
for (int i = 0; i < pot.pmCount(); i++)
{
assertEqual(128, pot.getValue(i));
}
assertFalse(pot.setValue(6, 10));
AD8400 p8400 = AD8400(10, 12, 13);