Advertisement
seston

ds3231

Apr 14th, 2015
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. // Date and time functions using RX8025 RTC connected via I2C and Wire lib
  2.  
  3. #include <Wire.h>
  4. #include "Sodaq_DS3231.h"
  5.  
  6. char weekDay[][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
  7.  
  8. void setup ()
  9. {
  10. Serial.begin(57600);
  11. Wire.begin();
  12. rtc.begin();
  13. }
  14.  
  15. uint32_t old_ts;
  16.  
  17. void loop ()
  18. {
  19. DateTime now = rtc.now(); //get the current date-time
  20. uint32_t ts = now.getEpoch();
  21.  
  22. if (old_ts == 0 || old_ts != ts) {
  23. old_ts = ts;
  24. Serial.print(now.year(), DEC);
  25. Serial.print('/');
  26. Serial.print(now.month(), DEC);
  27. Serial.print('/');
  28. Serial.print(now.date(), DEC);
  29. Serial.print(' ');
  30. Serial.print(now.hour(), DEC);
  31. Serial.print(':');
  32. Serial.print(now.minute(), DEC);
  33. Serial.print(':');
  34. Serial.print(now.second(), DEC);
  35. Serial.print(' ');
  36. Serial.print(weekDay[now.dayOfWeek()]);
  37. Serial.println();
  38. Serial.print("Seconds since Unix Epoch: ");
  39. Serial.print(ts, DEC);
  40. Serial.println();
  41. }
  42. delay(1000);
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement