|
| 1 | +/* |
| 2 | + advancedRTCAlarm |
| 3 | +
|
| 4 | + This sketch is an extension of simpleRTCAlarm. |
| 5 | + It uses the optional 'data' alarm callback parameters to |
| 6 | + reload alarm with 'atime' offset indefinitely. |
| 7 | +
|
| 8 | +
|
| 9 | + Creation 25 May 2018 |
| 10 | + by Frederic Pillon for STMicroelectronics |
| 11 | +
|
| 12 | + This example code is in the public domain. |
| 13 | +
|
| 14 | + https://github.com/stm32duino/STM32RTC |
| 15 | +
|
| 16 | +*/ |
| 17 | + |
| 18 | +#include <STM32RTC.h> |
| 19 | + |
| 20 | +/* Get the rtc object */ |
| 21 | +STM32RTC& rtc = STM32RTC::getInstance(); |
| 22 | + |
| 23 | +/* Declare it volatile since it's incremented inside an interrupt */ |
| 24 | +volatile int alarmMatch_counter = 0; |
| 25 | + |
| 26 | +/* Change this value to set alarm match offset */ |
| 27 | +static uint32_t atime = 5; |
| 28 | + |
| 29 | +/* Change these values to set the current initial time */ |
| 30 | +const byte seconds = 0; |
| 31 | +const byte minutes = 0; |
| 32 | +const byte hours = 16; |
| 33 | + |
| 34 | +/* Change these values to set the current initial date */ |
| 35 | +const byte day = 25; |
| 36 | +const byte month = 9; |
| 37 | +const byte year = 15; |
| 38 | + |
| 39 | +void setup() |
| 40 | +{ |
| 41 | + Serial.begin(9600); |
| 42 | + |
| 43 | + rtc.begin(); // initialize RTC 24H format |
| 44 | + |
| 45 | + rtc.setTime(hours, minutes, seconds); |
| 46 | + rtc.setDate(day, month, year); |
| 47 | + |
| 48 | + rtc.attachInterrupt(alarmMatch, &atime); |
| 49 | + rtc.setAlarmDay(day); |
| 50 | + rtc.setAlarmTime(16, 0, 10); |
| 51 | + rtc.enableAlarm(rtc.MATCH_DHHMMSS); |
| 52 | +} |
| 53 | + |
| 54 | +void loop() |
| 55 | +{ |
| 56 | + |
| 57 | +} |
| 58 | + |
| 59 | +void alarmMatch(void *data) |
| 60 | +{ |
| 61 | + uint32_t sec = 1; |
| 62 | + if(data != NULL) { |
| 63 | + sec = *(uint32_t*)data; |
| 64 | + // Minimum is 1 second |
| 65 | + if (sec == 0){ |
| 66 | + sec = 1; |
| 67 | + } |
| 68 | + } |
| 69 | + alarmMatch_counter++; |
| 70 | + Serial.print("Alarm Match "); |
| 71 | + Serial.println(alarmMatch_counter); |
| 72 | + rtc.setAlarmEpoch( rtc.getEpoch() + sec); |
| 73 | +} |
0 commit comments