Replace delay() with ISR_Timer

This commit is contained in:
cryptogopher
2022-09-12 00:07:37 +02:00
parent 3f5ce648d5
commit b81b52b204
3 changed files with 39 additions and 52 deletions

View File

@@ -1,11 +1,22 @@
volatile unsigned long lastButtonPress = millis();
void initButton() {
pinMode(BUTTON_PIN, INPUT_PULLUP);
// Order of ISRs matter: RISING should be invoked first
attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), buttonISRtime, CHANGE);
attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), buttonISRstate, RISING);
}
void buttonISRstate() {
if ((millis() - lastButtonPress) > 100) {
if (countdown > 0)
if (countdown < 0)
countdown = 0;
else
countdown = BREAK_LENGTH;
else if (countdown == 0)
countdown = COUNTDOWN;
else {
countdown = -1;
digitalWrite(BUTTON_LED_PIN, LOW);
}
}
}