Replace delay() with ISR_Timer
This commit is contained in:
17
button.ino
17
button.ino
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user