]> git.piffa.net Git - arduino/blob - books/pdummies/Libraries/RTClib/examples/softrtc/softrtc.pde
first commit
[arduino] / books / pdummies / Libraries / RTClib / examples / softrtc / softrtc.pde
1 // Date and time functions using just software, based on millis() & timer
2
3 #include <Wire.h>
4 #include "RTClib.h"
5
6 RTC_Millis RTC;
7
8 void setup () {
9     Serial.begin(57600);
10     // following line sets the RTC to the date & time this sketch was compiled
11     RTC.begin(DateTime(__DATE__, __TIME__));
12 }
13
14 void loop () {
15     DateTime now = RTC.now();
16     
17     Serial.print(now.year(), DEC);
18     Serial.print('/');
19     Serial.print(now.month(), DEC);
20     Serial.print('/');
21     Serial.print(now.day(), DEC);
22     Serial.print(' ');
23     Serial.print(now.hour(), DEC);
24     Serial.print(':');
25     Serial.print(now.minute(), DEC);
26     Serial.print(':');
27     Serial.print(now.second(), DEC);
28     Serial.println();
29     
30     Serial.print(" seconds since 1970: ");
31     Serial.println(now.unixtime());
32     
33     // calculate a date which is 7 days and 30 seconds into the future
34     DateTime future (now.unixtime() + 7 * 86400L + 30);
35     
36     Serial.print(" now + 7d + 30s: ");
37     Serial.print(future.year(), DEC);
38     Serial.print('/');
39     Serial.print(future.month(), DEC);
40     Serial.print('/');
41     Serial.print(future.day(), DEC);
42     Serial.print(' ');
43     Serial.print(future.hour(), DEC);
44     Serial.print(':');
45     Serial.print(future.minute(), DEC);
46     Serial.print(':');
47     Serial.print(future.second(), DEC);
48     Serial.println();
49     
50     Serial.println();
51     delay(3000);
52 }