How do you plan to solve it?
I used the OneButton library and used the functions included in the library like button.attachClick to trigger single click event. The reason why I used OneButton library is because I want to make the source code shorter and in order to avoid coding the millis function from scratch.
/*Paste your code here*/
#include <OneButton.h>
const int buttonPin = 7;
OneButton button(buttonPin, true); // true = active low (works with INPUT_PULLUP)
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
Serial.begin(9600);
// Attach functions to button events
button.attachClick(singleClick);
button.attachDoubleClick(doubleClick);
button.attachLongPressStart(longPress);
}
void loop() {
button.tick(); // update button
}
void singleClick() {
Serial.println("Single Click detected");
}
void doubleClick() {
Serial.println("Double Click detected");
}
void longPress() {
Serial.println("Long Press detected");
}
Add a video of the output (know more)
https://wokwi.com/projects/442502824921812993