#include <ezButton.h>
#define SHORT_PRESS_TIME 1000 // 1000 milliseconds
#define LONG_PRESS_TIME 1000 // 1000 milliseconds
ezButton button(21); // create ezButton object that attach to pin GPIO21
unsigned long pressedTime = 0;
unsigned long releasedTime = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
button.setDebounceTime(50); // set debounce time to 50 milliseconds
}
void loop() {
// put your main code here, to run repeatedly:
button.loop(); // MUST call loop() function first
if (button.isPressed())
pressedTime = millis();
if (button.isReleased()) {
releasedTime = millis();
long pressDuration = releasedTime - pressedTime;
if (pressDuration < SHORT_PRESS_TIME)
Serial.println("A short press is detected");
if (pressDuration > LONG_PRESS_TIME)
Serial.println("A long press is detected");
}
}