🛠 RTC timestamps and a minute alarm (no battery!)
Goal
Use the RA4M1 real-time clock to keep time, print a timestamp on every minute change, and fire an event (LED + serial line) as an alarm. Caveat up front: the board has no backup battery, so the clock restarts from the sketch value at every boot.
Code
#include "RTC.h"
RTCtime now;
uint8_t lastMinute = 255;
void setup {
Serial.begin(115200);
RTC.begin;
RTCtime t(2026, 10, 14, 8, 0, 0); // Y M D H M S, set once per boot
RTC.set(t);
}
void loop {
RTC.get(now);
if (now.minute != lastMinute) {
lastMinute = now.minute;
Serial.printf("%04d-%02d-%02d %02d:%02d:%02d\n",
now.year, now.month, now.dayofmonth,
now.hour, now.minute, now.second);
digitalWrite(13, !digitalRead(13)); // blink each minute
}
delay(100);
}
Expected result
One timestamp line per minute, LED toggling with it. Poll faster than once per minute or you will miss boundaries.
Common mistakes
- Expecting the time to survive a power cut: without a battery it resets each boot ; re-sync over Serial after upload.
- Calling RTC.set in loop: you freeze the clock.
- No daylight-saving logic in the library - handle it yourself.
Autres tutoriels pour cette carte
Exemples de code pour cette carte
clignotante.inoArduinobouton-poussoir.inoArduinodac-analogique.inoArduinoentree-analogique.inoArduinopwm-respiration.inoArduinoservo-balayage.inoArduino