All submissions

Single Double Click and Long Press Detection

Solving Approach

How do you plan to solve it?

 
 

 

 

 

Code

/*Paste your code here*/
#define PUSH_BUTTON_PIN  2
#define SESSION_PERIOD   1600
#define DEBOUNCING_DELAY 150


volatile int button_counter = 0;

unsigned long tick  = 0;


void setup() 
{
  // put your setup code here, to run once:
  pinMode(PUSH_BUTTON_PIN, INPUT_PULLUP);

  Serial.begin(115200);

}

void loop() 
{

  // open a session
  tick = millis(); // get the curren tick

  while((millis()-tick)<SESSION_PERIOD)
  {
    if(!digitalRead(PUSH_BUTTON_PIN))
    {
      button_counter++;
      delay(DEBOUNCING_DELAY);
    }
  }


    if(button_counter==1) 
    {
      Serial.println("Single click detected");
    } 
      

    else if(button_counter==2)
    {
      Serial.println("Double click detected");
    } 
   
    else if(button_counter>=3)
    {
      Serial.println("Long press detected");
    }

    button_counter = 0;
}

 

 

 

Output

Video

Add a video of the output (know more)

 

 

 

 

Submit Your Solution

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