|
| 1 | +/* |
| 2 | + * This example demonstrates how to use the periodic callback functionality of the RTC |
| 3 | + * (Real Time Clock) on the Portenta C33. |
| 4 | + * |
| 5 | + * It blinks the built-in LED at progressively faster and slower rates repeatedly. |
| 6 | + * |
| 7 | + */ |
| 8 | + |
| 9 | +#include "RTC.h" |
| 10 | + |
| 11 | +#define BLINK_DELAY 2000 |
| 12 | + |
| 13 | +// This is the callback function to be passed to RTC.setPeriodicCallback() |
| 14 | +void periodicCallback() |
| 15 | +{ |
| 16 | + static bool ledState = false; |
| 17 | + if (ledState == true) { |
| 18 | + digitalWrite(LED_BUILTIN, HIGH); |
| 19 | + } |
| 20 | + else { |
| 21 | + digitalWrite(LED_BUILTIN, LOW); |
| 22 | + } |
| 23 | + ledState = !ledState; |
| 24 | +} |
| 25 | + |
| 26 | +void setup() { |
| 27 | + pinMode(LED_BUILTIN, OUTPUT); |
| 28 | + |
| 29 | + Serial.begin(9600); |
| 30 | + while (!Serial) ; |
| 31 | + |
| 32 | + // Initialize the RTC |
| 33 | + RTC.begin(); |
| 34 | + |
| 35 | + // RTC.setTime() must be called for RTC.setPeriodicCallback to work, but it doesn't matter |
| 36 | + // what date and time it's set to |
| 37 | + RTCTime mytime(25, Month::AUGUST, 2022, 14, 37, 00, DayOfWeek::THURSDAY, SaveLight::SAVING_TIME_ACTIVE); |
| 38 | + RTC.setTime(mytime); |
| 39 | +} |
| 40 | + |
| 41 | +void loop() { |
| 42 | + Serial.println(RTC.setPeriodicCallback(periodicCallback, Period::ONCE_EVERY_1_SEC)); |
| 43 | + delay(BLINK_DELAY); |
| 44 | + Serial.println(RTC.setPeriodicCallback(periodicCallback, Period::N2_TIMES_EVERY_SEC)); |
| 45 | + delay(BLINK_DELAY); |
| 46 | + Serial.println(RTC.setPeriodicCallback(periodicCallback, Period::N4_TIMES_EVERY_SEC)); |
| 47 | + delay(BLINK_DELAY); |
| 48 | + Serial.println(RTC.setPeriodicCallback(periodicCallback, Period::N8_TIMES_EVERY_SEC)); |
| 49 | + delay(BLINK_DELAY); |
| 50 | + Serial.println(RTC.setPeriodicCallback(periodicCallback, Period::N16_TIMES_EVERY_SEC)); |
| 51 | + delay(BLINK_DELAY); |
| 52 | + Serial.println(RTC.setPeriodicCallback(periodicCallback, Period::N32_TIMES_EVERY_SEC)); |
| 53 | + delay(BLINK_DELAY); |
| 54 | + Serial.println(RTC.setPeriodicCallback(periodicCallback, Period::N16_TIMES_EVERY_SEC)); |
| 55 | + delay(BLINK_DELAY); |
| 56 | + Serial.println(RTC.setPeriodicCallback(periodicCallback, Period::N8_TIMES_EVERY_SEC)); |
| 57 | + delay(BLINK_DELAY); |
| 58 | + Serial.println(RTC.setPeriodicCallback(periodicCallback, Period::N4_TIMES_EVERY_SEC)); |
| 59 | + delay(BLINK_DELAY); |
| 60 | + Serial.println(RTC.setPeriodicCallback(periodicCallback, Period::N2_TIMES_EVERY_SEC)); |
| 61 | + delay(BLINK_DELAY); |
| 62 | + Serial.println(RTC.setPeriodicCallback(periodicCallback, Period::ONCE_EVERY_1_SEC)); |
| 63 | + delay(BLINK_DELAY); |
| 64 | +} |
0 commit comments