Move touch threshold to constructor

This commit is contained in:
Robert Marshall 2022-08-26 20:44:36 +01:00
parent 80fa2d9d60
commit 23101e1025
2 changed files with 6 additions and 7 deletions

View file

@ -4,24 +4,23 @@
#include <Arduino.h> #include <Arduino.h>
#include <functional> #include <functional>
#define TOUCH_THRESHOLD 20
class TouchInput { class TouchInput {
const unsigned int _debounceDelay = 50; const unsigned int _debounceDelay = 50;
int _pin; int _pin, _touchThreshold;
std::function<void()> _callback; std::function<void()> _callback;
unsigned long _touchStart; unsigned long _touchStart;
bool _currentTouchValue, _prevTouchValue; bool _currentTouchValue, _prevTouchValue;
public: public:
TouchInput(int pin, std::function<void()> callback){ TouchInput(int pin, int touchThreshold, std::function<void()> callback){
_pin = pin; _pin = pin;
_touchThreshold = touchThreshold;
_callback = callback; _callback = callback;
} }
void loop(){ void loop(){
bool touching = touchRead(_pin) <= TOUCH_THRESHOLD; bool touching = touchRead(_pin) <= _touchThreshold;
if (_prevTouchValue != touching) { if (_prevTouchValue != touching) {
_touchStart = millis(); _touchStart = millis();

View file

@ -31,11 +31,11 @@ LedManager _leds(&_timers);
BluetoothLightControl _bluetoothLightControl(&_leds); BluetoothLightControl _bluetoothLightControl(&_leds);
BluetoothLEDCallback _btCallback(&_bluetoothLightControl); BluetoothLEDCallback _btCallback(&_bluetoothLightControl);
BluetoothService _btService("Van Lights", &_btCallback); BluetoothService _btService("Van Lights", &_btCallback);
TouchInput _touchInput(32, []() { TouchInput _touchInput(33, 9, []() {
_seatingLeds.toggle(); _seatingLeds.toggle();
_kitchenLeds.toggle(); _kitchenLeds.toggle();
_bathroomLeds.toggle(); _bathroomLeds.toggle();
_awningLeds.toggle(); //_awningLeds.toggle();
_cabLeds.toggle(); _cabLeds.toggle();
}); });