Initial commit
This commit is contained in:
14
button.ino
Normal file
14
button.ino
Normal 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
32
metronom.ino
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user