Files
metronom/metronom.ino
2022-10-09 14:26:33 +02:00

33 lines
780 B
C++

const uint BUZZER_PIN = 0;
const uint BUTTON_LED_PIN = 5;
const uint BUTTON_PIN = 6;
const int BREAK_LENGTH = 240000;
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, 300, 100);
delay(1000);
}
}