Skip to content

Commit 00a929a

Browse files
add hysteresis
1 parent b4cee6e commit 00a929a

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Potentiometer_ADS1115/Potentiometer_ADS1115.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Potentiometer_ADS1115::Potentiometer_ADS1115(
1818
_rangeMax = range_max;
1919
_adc = adc;
2020
_callback = callback;
21+
22+
_filter = createDeadbandFilter(_widthOfDeadbandInBits);
2123
}
2224

2325
void Potentiometer_ADS1115::begin() {
@@ -37,6 +39,10 @@ void Potentiometer_ADS1115::read() {
3739
} else if (_channel == 3) {
3840
_val = _adc->readChannel3(_maxVoltage, _rangeMin, _rangeMax);
3941
}
42+
43+
// add hysteresis
44+
_val = deadband(_filter, _val);
45+
4046
if (_val != _prev) {
4147
_prev = _val;
4248
_callback.callbackIntArg(_val);

Potentiometer_ADS1115/Potentiometer_ADS1115.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <Arduino.h>
88
#include <Method.h>
9+
#include <Deadband.h>
910
#include <MultiPlexer_ADS1115.h>
1011

1112
class Potentiometer_ADS1115
@@ -30,8 +31,10 @@ class Potentiometer_ADS1115
3031
int16_t _rangeMin;
3132
int16_t _rangeMax;
3233
int16_t _maxVoltage;
33-
34+
const int _widthOfDeadbandInBits = 1;
35+
3436
Method _callback;
37+
DeadbandFilter* _filter;
3538
MultiPlexer_ADS1115* _adc;
3639
};
3740

0 commit comments

Comments
 (0)