Initial commit

This commit is contained in:
cryptogopher
2022-09-08 22:54:21 +02:00
commit 4a46ee65b9
2 changed files with 46 additions and 0 deletions

14
button.ino Normal file
View File

@@ -0,0 +1,14 @@
volatile unsigned long lastButtonPress = millis();
void buttonISRstate() {
if ((millis() - lastButtonPress) > 100) {
if (countdown > 0)
countdown = 0;
else
countdown = BREAK_LENGTH;
}
}
void buttonISRtime() {
lastButtonPress = millis();
}

32
metronom.ino Normal file
View File

@@ -0,0 +1,32 @@
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);
}
}