33 lines
781 B
C++
33 lines
781 B
C++
const uint BUZZER_PIN = 0;
|
|
|
|
const uint BUTTON_LED_PIN = 5;
|
|
const uint BUTTON_PIN = 6;
|
|
|
|
const int BREAK_LENGTH = 300000;
|
|
const int BREAK_STEP = 2000;
|
|
|
|
volatile int countdown = 0;
|
|
int step;
|
|
|
|
void setup() {
|
|
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 loop() {
|
|
if (countdown > 0) {
|
|
step = min(BREAK_STEP, countdown);
|
|
countdown -= step;
|
|
|
|
digitalWrite(BUTTON_LED_PIN, HIGH);
|
|
delay(min(BREAK_STEP/2, step));
|
|
digitalWrite(BUTTON_LED_PIN, LOW);
|
|
delay(max(step-BREAK_STEP/2, 0));
|
|
} else {
|
|
tone(BUZZER_PIN, 1000, 100);
|
|
delay(1000);
|
|
}
|
|
}
|