Is there a way to achieve, executing multiple events with a single Button Widget?
Like this…
Single Press: Event 1
Double Press: Event 2
Press & Hold: Event 3
Press & Long Hold: Event 4
Managed to implement Press & Hold Event with this code:
int longPressMillis = 1000; // time in millis needed for longpress
int longPressTimer;
boolean buttonState = false;
BLYNK_WRITE(V11)
{
if (param.asInt() == 1) { // if button is pressed
longPressTimer = timer.setTimeout(longPressMillis, onOffToggle); // start the timer to run the function in defined time
} else {
timer.deleteTimer(longPressTimer); // Stop and delete the timer if button is released to early
}
}
void onOffToggle() {
if (buttonState == true) {
// do something if true
buttonState = false;
Serial.println("Turned Off");
} else {
// do something if not true
buttonState = true;
Serial.println("Turned On");
}
}