Multiple clicks & events with Button Widget possible?

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");
  }
}

Short answer yes :wink: via code and timers.

You already found @jamin’s method

And I suppose by using variants of timers and counters you could get any reaction… I haven’t found it yet, but @Jamin also made some code that responds to coded button presses.

1 Like

Ah, found it…

1 Like

I suppose you could even use a table of Morse Code like taps and based on the code run differing events using Switch Case. My brains be too foggy to crank out any code tonight, so all I have are ideas :sleeping:

Cool! Thanks for the ideas. I’ll try to do implement these and will get back if I’m stuck :wink: