#include <ezButton.h>
const word threshold = 1000;
unsigned long pressed = 0;
ezButton button(2);
void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
button.setDebounceTime(50);
}
void loop() {
button.loop();
if (button.isPressed()) pressed = millis();
// shorthand
// if (button.isReleased()) digitalWrite(LED_BUILTIN, millis() - pressed < threshold ? 1 : 0);
// longhand
if (button.isReleased()) {
if (millis() - pressed < threshold) {
digitalWrite(LED_BUILTIN, HIGH);
Serial.println("short press = LED ON");
}else{
digitalWrite(LED_BUILTIN, LOW);
Serial.println("long press = LED OFF");
}
}
}
short press = LED ON
long press = LED OFF
youtu.be/ZVi2sZmKaaA