48 lines
993 B
C++
48 lines
993 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 = 240;
|
|
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;
|
|
volatile float temperature = 0.0;
|
|
|
|
void setup() {
|
|
initButton();
|
|
initTemperature();
|
|
initTube();
|
|
|
|
ITimer.attachInterruptInterval_MS(10, TimerHandler);
|
|
ISR_Timer.setInterval(PERIOD_MS, runMetronome);
|
|
ISR_Timer.setInterval(PERIOD_MS, readTemperature);
|
|
ISR_Timer.setInterval(PERIOD_MS, updateTube);
|
|
}
|
|
|
|
void runMetronome() {
|
|
if (countdown > 0) {
|
|
countdown -= 1;
|
|
|
|
digitalWrite(BUTTON_LED_PIN, countdown % 2 ? HIGH : LOW);
|
|
} else if (countdown == 0) {
|
|
//tone(BUZZER_PIN, 300, 100);
|
|
}
|
|
}
|
|
|
|
void loop() {}
|