const int BTN_PIN = 13;
const int LED_PIN = 15;
bool pressed;
unsigned long button_time = 0;
unsigned long last_button_time = 0;
void doCriticalThing() {
digitalWrite(LED_PIN, HIGH);
delay(225);
digitalWrite(LED_PIN, LOW);
delay(225);
}
void IRAM_ATTR isr() {
button_time = millis();
if ((button_time - last_button_time) > 500) {
pressed = true;
}
last_button_time = button_time;
}
void setup() {
pinMode(LED_PIN, OUTPUT);
pinMode(BTN_PIN, INPUT_PULLUP);
attachInterrupt(BTN_PIN, isr, FALLING);
}
void loop() {
if (pressed) {
doCriticalThing();
pressed = false;
}
}