forked from irbreeves/MeOws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adjustRTC.ino
44 lines (37 loc) · 1.17 KB
/
adjustRTC.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Date and time functions using a RX8025 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "Sodaq_DS3231.h"
char weekDay[][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
//year, month, date, hour, min, sec and week-day(starts from 0 and goes to 6)
//writing any non-existent time-data may interfere with normal operation of the RTC.
//Take care of week-day also. Monday is 1, Tuesday 2, etc.
//Takes ~7 seconds to upload!
//24 Hour clock!
//Must use double-0 not single 0
DateTime dt(2019, 8, 21, 19, 16, 00, 3);
void setup ()
{
Serial.begin(57600);
Wire.begin();
rtc.begin();
rtc.setDateTime(dt); //Adjust date-time as defined 'dt' above
}
void loop ()
{
DateTime now = rtc.now(); //get the current date-time
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.date(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
Serial.print(weekDay[now.dayOfWeek()]);
Serial.println();
delay(1000);
}