// off delay timer
uint32_t timer_preset = 3000; // three second delay
uint32_t current_millis;
const uint8_t pb1 = A0;
const uint8_t led_pin = 5;
uint8_t button_state;
void setup() {
Serial.begin(115200);
delay(300);
pinMode(led_pin, OUTPUT);
pinMode(pb1, INPUT);
}
void loop() {
button_state = digitalRead(pb1);
if (button_state == HIGH) {
current_millis = millis(); // timer is held reset
}
if (millis() - current_millis < timer_preset) {
digitalWrite(led_pin, HIGH);
}
else digitalWrite(led_pin, LOW);
}