Single Double Click and Long Press Detection

Solving Approach

How do you plan to solve it?

 
 

 

 

 

Code

/*Paste your code here*/

#include "OneButton.h"

void setup()

{

  pinMode(LED_BUILTIN, OUTPUT);

  pinMode(6, OUTPUT);


 

 OneButton button(6, true, true); 

button.attachClick([]() {

    Serial.println("Single Click Detected");

  });


 

  // Double Click

  button.attachDoubleClick([]() {

    Serial.println("Double Click Detected");

  });

   button.attachLongPressStart([]() {

    Serial.println("Long Press Started");

  });

}


 

void loop()

{

  digitalWrite(LED_BUILTIN, HIGH);

  delay(1000); // Wait for 1000 millisecond(s)

  digitalWrite(LED_BUILTIN, LOW);

  delay(1000); // Wait for 1000 millisecond(s)

    button.tick();

}

 

 

Output

Video

Add a video of the output (know more)

 

 

 

Upvote
Downvote

Submit Your Solution

Note: Once submitted, your solution goes public, helping others learn from your approach!