forked from hadefuwa/elegoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DS1307_Example.ino
54 lines (42 loc) · 1.2 KB
/
DS1307_Example.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
45
46
47
48
49
50
51
52
53
54
//www.elegoo.com
//2018.10.24
#include <Wire.h>
#include <DS3231.h>
DS3231 clock;
RTCDateTime dt;
void setup()
{
Serial.begin(9600);
Serial.println("Initialize RTC module");
// Initialize DS1307
clock.begin();
// Manual (YYYY, MM, DD, HH, II, SS
//clock.setDateTime(2016, 12, 9, 11, 46, 00);
// Send sketch compiling time to Arduino
clock.setDateTime(__DATE__, __TIME__);
/*
Tips:This command will be executed every time when Arduino restarts.
Comment this line out to store the memory of DS3231 module
*/
}
void loop()
{
dt = clock.getDateTime();
// For leading zero look to DS3231_dateformat example
Serial.print("Raw data: ");
Serial.print(dt.year); Serial.print("-");
Serial.print(dt.month); Serial.print("-");
Serial.print(dt.day); Serial.print(" ");
Serial.print(dt.hour); Serial.print(":");
Serial.print(dt.minute); Serial.print(":");
Serial.print(dt.second); Serial.println("");
if (dt.hour == 8 && dt.minute == 57 && dt.second == 0)
{
Serial.print("Wake up fatty!\n");
}
if (dt.year == 2022)
{
Serial.print("How did we make it through 2021???");
}
delay(1000);
}