#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 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); initTemperature(); ITimer.attachInterruptInterval_MS(10, TimerHandler); ISR_Timer.setInterval(1000, readTemperature); } 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); } }