From 38e08be7520d27bf50b9ed4eb8e74305dfb9346a Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Sat, 3 Feb 2024 14:58:49 +0100 Subject: [PATCH] button should always be input --- lib/PButton/PButon.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/PButton/PButon.cpp b/lib/PButton/PButon.cpp index dfbf4f898..61b8001d2 100644 --- a/lib/PButton/PButon.cpp +++ b/lib/PButton/PButon.cpp @@ -55,7 +55,7 @@ bool PButton::init(uint8_t pin, bool pullMode) { #if defined(ESP32) pinMode(pin_, pullMode ? INPUT_PULLUP : INPUT_PULLDOWN); -#else // esp8266 and standalone +#else // esp8266 and standalone pinMode(pin_, pullMode ? INPUT_PULLUP : INPUT); #endif enabled_ = (digitalRead(pin_) == pullMode); // see if a button is connected @@ -91,6 +91,12 @@ bool PButton::check(void) { int resultEvent = 0; long millisRes = millis(); + // make sure the pin is still input +#if defined(ESP32) + pinMode(pin_, pullMode_ ? INPUT_PULLUP : INPUT_PULLDOWN); +#else // esp8266 and standalone + pinMode(pin_, pullMode_ ? INPUT_PULLUP : INPUT); +#endif state_ = digitalRead(pin_) == pullMode_; // Button pressed down