From 23101e102551dc9b5170e475c40e51dc0ba119ba Mon Sep 17 00:00:00 2001 From: Robert Marshall Date: Fri, 26 Aug 2022 20:44:36 +0100 Subject: [PATCH] Move touch threshold to constructor --- src/TouchInput.cpp | 9 ++++----- src/main.cpp | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/TouchInput.cpp b/src/TouchInput.cpp index 1df4c85..f0309ac 100644 --- a/src/TouchInput.cpp +++ b/src/TouchInput.cpp @@ -4,24 +4,23 @@ #include #include -#define TOUCH_THRESHOLD 20 - class TouchInput { const unsigned int _debounceDelay = 50; - int _pin; + int _pin, _touchThreshold; std::function _callback; unsigned long _touchStart; bool _currentTouchValue, _prevTouchValue; public: - TouchInput(int pin, std::function callback){ + TouchInput(int pin, int touchThreshold, std::function 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(); diff --git a/src/main.cpp b/src/main.cpp index 42701e7..0020356 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -31,11 +31,11 @@ LedManager _leds(&_timers); BluetoothLightControl _bluetoothLightControl(&_leds); BluetoothLEDCallback _btCallback(&_bluetoothLightControl); BluetoothService _btService("Van Lights", &_btCallback); -TouchInput _touchInput(32, []() { +TouchInput _touchInput(33, 9, []() { _seatingLeds.toggle(); _kitchenLeds.toggle(); _bathroomLeds.toggle(); - _awningLeds.toggle(); + //_awningLeds.toggle(); _cabLeds.toggle(); });