diff options
author | Mike Beattie <mike@ethernal.org> | 2012-03-20 23:25:17 +1300 |
---|---|---|
committer | Mike Beattie <mike@ethernal.org> | 2012-03-20 23:25:17 +1300 |
commit | cb7bd533cb2b505441ca9a35c9897db358a30b47 (patch) | |
tree | fd20d304a519730798433e9835ce3e8e12f703fc /Time/Examples/TimeRTC/TimeRTC.pde |
Add Time library
Signed-off-by: Mike Beattie <mike@ethernal.org>
Diffstat (limited to 'Time/Examples/TimeRTC/TimeRTC.pde')
-rw-r--r-- | Time/Examples/TimeRTC/TimeRTC.pde | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/Time/Examples/TimeRTC/TimeRTC.pde b/Time/Examples/TimeRTC/TimeRTC.pde new file mode 100644 index 0000000..1a1ed80 --- /dev/null +++ b/Time/Examples/TimeRTC/TimeRTC.pde @@ -0,0 +1,47 @@ +/* + * TimeRTC.pde + * example code illustrating Time library with Real Time Clock. + * + */ + +#include <Time.h> +#include <Wire.h> +#include <DS1307RTC.h> // a basic DS1307 library that returns time as a time_t + +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); +} +
|