Skip to content

Commit 4e81841

Browse files
author
Evert Arias
authored
Merge pull request #45 from eppfel/master
Add ADC filter to remove jitters on touchRead
2 parents 6b5da60 + 047fd17 commit 4e81841

File tree

4 files changed

+52
-5
lines changed

4 files changed

+52
-5
lines changed

library.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "EasyButton",
3+
"keywords": "IO, button, sensor, arduino",
4+
"description": "EasyButton is an small Arduino library for debouncing momentary contact switches like tactile buttons. It uses events and callbacks to trigger actions when a button is pressed once or held for a given duration. It also provides a sequence counter to be able to rise an event when a given pattern of presses has been matched.",
5+
"version": "2.0.1",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/evert-arias/EasyButton"
9+
},
10+
"url": "https://easybtn.earias.me",
11+
"frameworks": "arduino",
12+
"platforms": "espressif8266, espressif32",
13+
"dependencies": [
14+
{
15+
"owner": "megunolink",
16+
"name": "MegunoLink",
17+
"version": "^1.33"
18+
}
19+
],
20+
"authors": [
21+
{
22+
"name": "Evert Arias",
23+
"email": "[email protected]"
24+
},
25+
{
26+
"name": "Felix A. Epp",
27+
"url": "https://github.com/eppfel"
28+
}
29+
]
30+
}

library.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ sentence=Arduino library for debouncing momentary contact switches, detect press
66
paragraph=EasyButton is an small Arduino library for debouncing momentary contact switches like tactile buttons. It uses events and callbacks to trigger actions when a button is pressed once or held for a given duration. It also provides a sequence counter to be able to rise an event when a given pattern of presses has been matched.
77
category=Signal Input/Output
88
url=https://easybtn.earias.me
9-
architectures=*
9+
architectures=*
10+
depends=MegunoLink

src/EasyButtonTouch.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
/**
22
* EasyButtonTouch.cpp
3-
* @author Evert Arias, Gutierrez PS
3+
* @author Evert Arias, Gutierrez PS, Felix A. Epp
44
* @version 2.0.0
55
* @license MIT
66
*/
77

88
#if defined(ESP32)
99
#include "EasyButtonTouch.h"
1010

11+
void EasyButtonTouch::setThreshold(int threshold)
12+
{
13+
_touch_threshold = threshold;
14+
}
15+
16+
void EasyButtonTouch::begin(int threshold)
17+
{
18+
_touch_threshold = threshold;
19+
begin();
20+
}
21+
1122
void EasyButtonTouch::begin()
1223
{
1324
_current_state = _readPin();
@@ -19,7 +30,8 @@ void EasyButtonTouch::begin()
1930

2031
bool EasyButtonTouch::_readPin()
2132
{
22-
return touchRead(_pin) < _touch_threshold;
33+
ADCFilter.Filter(touchRead(_pin));
34+
return ADCFilter.Current() < _touch_threshold;
2335
}
2436

2537
#endif

src/EasyButtonTouch.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* EasyButtonTouch.h
3-
* @author Evert Arias, Gutierrez PS
3+
* @author Evert Arias, Gutierrez PS, Felix A. Epp
44
* @version 2.0.0
55
* @license MIT
66
*/
@@ -9,16 +9,20 @@
99
#define _EasyButtonTouch_h
1010

1111
#include <Arduino.h>
12+
#include <Filter.h>
1213
#include "EasyButton.h"
1314

1415
class EasyButtonTouch : public EasyButton
1516
{
1617
public:
17-
EasyButtonTouch(uint8_t pin, uint32_t debounce_time = 35, uint16_t threshold = 50) : EasyButton(pin, debounce_time, false, false), _touch_threshold(threshold) {}
18+
EasyButtonTouch(uint8_t pin, uint32_t debounce_time = 35, uint16_t threshold = 50) : EasyButton(pin, debounce_time, false, false), _touch_threshold(threshold), ADCFilter(5, threshold) {}
1819
void begin();
20+
void begin(int threshold);
21+
void setThreshold(int threshold);
1922

2023
private:
2124
uint16_t _touch_threshold; // If touchRead() is below the threshold, the button is considered pressed.
25+
ExponentialFilter<long> ADCFilter;
2226

2327
bool _readPin();
2428
};

0 commit comments

Comments
 (0)