Move to new folder in preparation for more controllers
This commit is contained in:
parent
bcea2ee550
commit
ae3c20b59d
18 changed files with 59 additions and 4 deletions
|
@ -1,39 +0,0 @@
|
|||
#ifndef TouchInput_cpp
|
||||
#define TouchInput_cpp
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <functional>
|
||||
|
||||
class TouchInput {
|
||||
const unsigned int _debounceDelay = 50;
|
||||
|
||||
int _pin, _touchThreshold;
|
||||
std::function<void()> _callback;
|
||||
unsigned long _touchStart;
|
||||
bool _currentTouchValue, _prevTouchValue;
|
||||
|
||||
public:
|
||||
TouchInput(int pin, int touchThreshold, std::function<void()> callback){
|
||||
_pin = pin;
|
||||
_touchThreshold = touchThreshold;
|
||||
_callback = callback;
|
||||
}
|
||||
|
||||
void loop(){
|
||||
bool touching = touchRead(_pin) <= _touchThreshold;
|
||||
|
||||
if (_prevTouchValue != touching) {
|
||||
_touchStart = millis();
|
||||
}
|
||||
|
||||
if (millis() - _touchStart >= _debounceDelay && touching != _currentTouchValue){
|
||||
_currentTouchValue = touching;
|
||||
if (touching)
|
||||
_callback();
|
||||
}
|
||||
|
||||
_prevTouchValue = touching;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue