Move touch threshold to constructor
This commit is contained in:
parent
80fa2d9d60
commit
23101e1025
2 changed files with 6 additions and 7 deletions
|
@ -4,24 +4,23 @@
|
|||
#include <Arduino.h>
|
||||
#include <functional>
|
||||
|
||||
#define TOUCH_THRESHOLD 20
|
||||
|
||||
class TouchInput {
|
||||
const unsigned int _debounceDelay = 50;
|
||||
|
||||
int _pin;
|
||||
int _pin, _touchThreshold;
|
||||
std::function<void()> _callback;
|
||||
unsigned long _touchStart;
|
||||
bool _currentTouchValue, _prevTouchValue;
|
||||
|
||||
public:
|
||||
TouchInput(int pin, std::function<void()> callback){
|
||||
TouchInput(int pin, int touchThreshold, std::function<void()> callback){
|
||||
_pin = pin;
|
||||
_touchThreshold = touchThreshold;
|
||||
_callback = callback;
|
||||
}
|
||||
|
||||
void loop(){
|
||||
bool touching = touchRead(_pin) <= TOUCH_THRESHOLD;
|
||||
bool touching = touchRead(_pin) <= _touchThreshold;
|
||||
|
||||
if (_prevTouchValue != touching) {
|
||||
_touchStart = millis();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue