From 7ecff55f9ce99d67009f08c7582ecddb9ac5a08f Mon Sep 17 00:00:00 2001 From: Gregg Date: Sat, 3 Oct 2020 12:02:57 -0500 Subject: [PATCH] Updated PushButton() so that longPresses always repeat No need for any new methods - default is now that longPress repeats every longTime milliseconds provided button continues to be held down. Once a longPress is triggered, a shortPress will not be triggered until button is released. --- .../D-Expert/15-RealPushButtons/15-RealPushButtons.ino | 2 +- src/Utils.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/Tutorials/D-Expert/15-RealPushButtons/15-RealPushButtons.ino b/examples/Tutorials/D-Expert/15-RealPushButtons/15-RealPushButtons.ino index c7bbd00..44eee77 100644 --- a/examples/Tutorials/D-Expert/15-RealPushButtons/15-RealPushButtons.ino +++ b/examples/Tutorials/D-Expert/15-RealPushButtons/15-RealPushButtons.ino @@ -94,7 +94,7 @@ void setup() { new SpanAccessory(); new DEV_Identify("PushButton LED","HomeSpan","123-ABC","20mA LED","0.9",0); - new DEV_DimmableLED(0,17,23,5,18); // NEW! added three extra arguments to specific the pin numbers for three SpanButtons() - see DEV_LED.h + new DEV_DimmableLED(0,17,23,5,18); // NEW! added three extra arguments to specify the pin numbers for three SpanButtons() - see DEV_LED.h } // end of setup() diff --git a/src/Utils.cpp b/src/Utils.cpp index 2c179a9..2686496 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -99,6 +99,7 @@ boolean PushButton::triggered(uint16_t shortTime, uint16_t longTime){ } else if(millis()>longAlarm){ // button is long-pressed + longAlarm=millis()+longTime; status=3; isLongPress=true; return(true); @@ -108,6 +109,11 @@ boolean PushButton::triggered(uint16_t shortTime, uint16_t longTime){ case 3: if(digitalRead(pin)) // button has been released after a long press status=0; + else if(millis()>longAlarm){ + longAlarm=millis()+longTime; + isLongPress=true; + return(true); + } break; }