diff --git a/libraries/RTC/examples/RTC_AutomaticExample/RTC_AutomaticExample.ino b/libraries/RTC/examples/RTC_AutomaticExample/RTC_AutomaticExample.ino index cca5063d..5d9dbda9 100644 --- a/libraries/RTC/examples/RTC_AutomaticExample/RTC_AutomaticExample.ino +++ b/libraries/RTC/examples/RTC_AutomaticExample/RTC_AutomaticExample.ino @@ -17,6 +17,8 @@ // Include the RTC library #include "RTC.h" +bool alarmFlag = false; + DayOfWeek convertDayOfWeek(String s) { if (s == String("Mon")) @@ -139,20 +141,7 @@ RTCTime currentRTCTime() } void alarmCallback() { - Serial.println("An alarm was triggered at:"); - RTCTime currentTime; - RTC.getTime(currentTime); - Serial.print(currentTime.getYear()); - Serial.print("-"); - Serial.print(Month2int(currentTime.getMonth())); - Serial.print("-"); - Serial.print(currentTime.getDayOfMonth()); - Serial.print(" "); - Serial.print(currentTime.getHour()); - Serial.print(":"); - Serial.print(currentTime.getMinutes()); - Serial.print(":"); - Serial.println(currentTime.getSeconds()); + alarmFlag = true; } void setup() @@ -195,4 +184,21 @@ void setup() void loop() { + if(alarmFlag){ + Serial.println("An alarm was triggered at:"); + RTCTime currentTime; + RTC.getTime(currentTime); + Serial.print(currentTime.getYear()); + Serial.print("-"); + Serial.print(Month2int(currentTime.getMonth())); + Serial.print("-"); + Serial.print(currentTime.getDayOfMonth()); + Serial.print(" "); + Serial.print(currentTime.getHour()); + Serial.print(":"); + Serial.print(currentTime.getMinutes()); + Serial.print(":"); + Serial.println(currentTime.getSeconds()); + alarmFlag = false; + } } diff --git a/libraries/RTC/examples/Test_RTC/Test_RTC.ino b/libraries/RTC/examples/Test_RTC/Test_RTC.ino index 4fccdc68..5bf50ccc 100644 --- a/libraries/RTC/examples/Test_RTC/Test_RTC.ino +++ b/libraries/RTC/examples/Test_RTC/Test_RTC.ino @@ -14,29 +14,19 @@ // Define the interrupt pin for LED control during interrupts const int LED_ON_INTERRUPT = 22; +bool periodicFlag = false; +bool alarmFlag = false; + // Callback function for periodic interrupt void periodic_cbk() { - static bool clb_st = false; - - // Toggle the LED based on callback state - if (clb_st) { - digitalWrite(LED_ON_INTERRUPT, HIGH); - } - else { - digitalWrite(LED_ON_INTERRUPT, LOW); - } - - clb_st = !clb_st; // Toggle callback state - - // Print message indicating periodic interrupt - Serial.println("PERIODIC INTERRUPT"); + periodicFlag = true; } +// Callback function for alarm interrupt void alarm_cbk() { - Serial.println("ALARM INTERRUPT"); + alarmFlag = true; } -// Callback function for alarm interrupt void setup() { // Initialize serial communication Serial.begin(9600); @@ -91,6 +81,33 @@ void loop() { RTCTime currenttime; + if(periodicFlag){ + // Print message indicating periodic interrupt + Serial.println("PERIODIC INTERRUPT"); + + static bool clb_st = false; + + // Toggle the LED based on callback state + if (clb_st) { + digitalWrite(LED_ON_INTERRUPT, HIGH); + } + else { + digitalWrite(LED_ON_INTERRUPT, LOW); + } + + clb_st = !clb_st; // Toggle callback state + + periodicFlag = false; + } + + if(alarmFlag){ + // Print message indicating alarm interrupt + Serial.println("ALARM INTERRUPT"); + + alarmFlag = false; + } + + // Check if RTC is running and print status if (status) {