Files
metronom/metronom.ino
cryptogopher 3872ece37b Join ISRs
2022-10-09 14:40:33 +02:00

42 lines
823 B
C++

#include "SAMDTimerInterrupt.h"
#include "SAMD_ISR_Timer.h"
#define HW_TIMER_INTERVAL_MS 10
SAMDTimer ITimer(TIMER_TC3);
SAMD_ISR_Timer ISR_Timer;
void TimerHandler(void) { ISR_Timer.run(); }
const int COUNTDOWN = 300;
const int PERIOD_MS = 1000;
const uint BUTTON_PIN = 6;
const uint BUTTON_LED_PIN = 5;
const uint BUZZER_PIN = 0;
/* Metronome state is expressed by countdown:
* -1 - IDLE
* 0 - BEATING
* >0 - COUNTDOWN
*/
volatile int countdown = -1;
void setup() {
initButton();
ITimer.attachInterruptInterval_MS(10, TimerHandler);
ISR_Timer.setInterval(PERIOD_MS, metronomeRun);
}
void metronomeRun() {
if (countdown > 0) {
countdown -= 1;
digitalWrite(BUTTON_LED_PIN, countdown % 2 ? HIGH : LOW);
} else if (countdown == 0) {
//tone(BUZZER_PIN, 1000, 100);
}
}
void loop() {}