Add ESP32 touch sensors as button alternative (#1190)

* Add touch option to button handler

* Check if touch is pressed in setup

* Add TOUCHPIN build env and override example

Co-authored-by: Aircoookie <dev.aircoookie@gmail.com>
pull/1193/head
Jake 2020-09-20 16:12:46 +02:00 zatwierdzone przez GitHub
rodzic 1313a44ba3
commit a3e1af72ab
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
6 zmienionych plików z 29 dodań i 6 usunięć

Wyświetl plik

@ -334,6 +334,14 @@ lib_ignore =
ESPAsyncTCP
ESPAsyncUDP
[env:custom32_TOUCHPIN_T0]
board = esp32dev
platform = espressif32@1.12.4
build_flags = ${common.build_flags_esp32} -D TOUCHPIN=T0
lib_ignore =
ESPAsyncTCP
ESPAsyncUDP
[env:wemos_shield_esp32]
board = esp32dev
platform = espressif32@1.12.4

Wyświetl plik

@ -21,6 +21,7 @@ build_flags = ${common.build_flags_esp8266}
; PIN defines - uncomment and change, if needed:
; -D LEDPIN=2
; -D BTNPIN=0
; -D TOUCHPIN=T0
; -D IR_PIN=4
; -D RLYPIN=12
; -D RLYMDE=1

Wyświetl plik

@ -15,13 +15,24 @@ void shortPressAction()
}
}
bool isButtonPressed()
{
#ifdef BTNPIN
if (digitalRead(BTNPIN) == LOW) return true;
#endif
#ifdef TOUCHPIN
if (touchRead(TOUCHPIN) <= TOUCH_THRESHOLD) return true;
#endif
return false;
}
void handleButton()
{
#ifdef BTNPIN
#if defined(BTNPIN) || defined(TOUCHPIN)
if (!buttonEnabled) return;
if (digitalRead(BTNPIN) == LOW) //pressed
if (isButtonPressed()) //pressed
{
if (!buttonPressedBefore) buttonPressedTime = millis();
buttonPressedBefore = true;
@ -37,7 +48,7 @@ void handleButton()
}
}
}
else if (digitalRead(BTNPIN) == HIGH && buttonPressedBefore) //released
else if (!isButtonPressed() && buttonPressedBefore) //released
{
long dur = millis() - buttonPressedTime;
if (dur < 50) {buttonPressedBefore = false; return;} //too short "press", debounce

Wyświetl plik

@ -126,6 +126,8 @@
#define ABL_MILLIAMPS_DEFAULT 850; // auto lower brightness to stay close to milliampere limit
#define TOUCH_THRESHOLD 32 // limit to recognize a touch, higher value means more sensitive
// Size of buffer for API JSON object (increase for more segments)
#ifdef ESP8266
#define JSON_BUFFER_SIZE 9216

Wyświetl plik

@ -21,6 +21,7 @@ void updateBlynk();
//button.cpp
void shortPressAction();
bool isButtonPressed();
void handleButton();
void handleIO();

Wyświetl plik

@ -250,8 +250,8 @@ void WLED::beginStrip()
#endif
// disable button if it is "pressed" unintentionally
#ifdef BTNPIN
if (digitalRead(BTNPIN) == LOW)
#if defined(BTNPIN) || defined(TOUCHPIN)
if (isButtonPressed())
buttonEnabled = false;
#else
buttonEnabled = false;