forked from JChristensen/MCP79412RTC
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeRTC.ino
More file actions
50 lines (45 loc) · 1.33 KB
/
TimeRTC.ino
File metadata and controls
50 lines (45 loc) · 1.33 KB
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
// Arduino MCP79412RTC Library
// https://github.com/JChristensen/MCP79412RTC
// TimeRTC.ino
// Example code illustrating Time library with Real Time Clock.
// This example is identical to the example provided with the Time Library,
// only the #include statement has been changed to include the MCP79412RTC library.
#include <MCP79412RTC.h> // http://github.com/JChristensen/MCP79412RTC
#include <TimeLib.h> // https://www.pjrc.com/teensy/td_libs_DS1307RTC.html
#include <Wire.h> // https://www.arduino.cc/en/Reference/Wire
void setup()
{
Serial.begin(9600);
setSyncProvider(RTC.get); // the function to get the time from the RTC
if(timeStatus()!= timeSet)
Serial.println("Unable to sync with the RTC");
else
Serial.println("RTC has set the system time");
}
void loop()
{
digitalClockDisplay();
delay(1000);
}
void digitalClockDisplay()
{
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.print(" ");
Serial.print(day());
Serial.print(" ");
Serial.print(month());
Serial.print(" ");
Serial.print(year());
Serial.println();
}
void printDigits(int digits)
{
// utility function for digital clock display: prints preceding colon and leading 0
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}