en-us_commands:reference:irtcset
This is an old revision of the document!
Table of Contents
IrtcSet()
IrtcSet() sets the RTC date and time.
bool IrtcSet(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second)
bool IrtcSet(uint16_t year, uint8_t month, uint8_t day, uint8_t dayOfWeek, uint8_t hour, uint8_t minute, uint8_t second)
Commands
| Command | Arguments | Return Value | Operation |
|---|---|---|---|
IrtcSet(year, month, day, hour, minute, second) | uint16_t year — 2000~2099uint8_t month — 1~12uint8_t day — Valid day of the specified monthuint8_t hour — 0~23uint8_t minute — 0~59uint8_t second — 0~59 | bool | Sets the RTC date and time. |
Example
void setup() { Serial.begin(115200); if (!IrtcBegin()) { Serial.println(F("DS3231 connection failed")); return; } // Run once initially, then comment out. // IrtcSet(2026, 8, 10, 14, 30, 0); } void loop() { IrtcDateTime now; if (IrtcRead(now)) { Serial.print(now.year); Serial.print('/'); Serial.print(now.month); Serial.print('/'); Serial.print(now.day); Serial.print(' '); Serial.print(now.hour); Serial.print(':'); Serial.print(now.minute); Serial.print(':'); Serial.println(now.second); } delay(1000); }
Precautions
Run each device's corresponding Begin command first. Check I²C addresses and pin sharing; if the bool return value is false, inspect wiring and power.
en-us_commands/reference/irtcset.1788785568.txt.gz · Last modified: by 127.0.0.1
