Advertisement
Guest User

Untitled

a guest
Oct 9th, 2015
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. #include <Wire.h>
  2. #include "RTClib.h"
  3.  
  4. RTC_DS1307 rtc;
  5.  
  6. void setup () {
  7. Serial.begin(57600);
  8. Wire.begin();
  9. rtc.begin();
  10.  
  11. if (! rtc.isrunning()) {
  12. Serial.println("RTC is NOT running!");
  13. // following line sets the RTC to the date & time this sketch was compiled
  14. //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  15. // This line sets the RTC with an explicit date & time, for example to set
  16. // January 21, 2014 at 3am you would call:
  17. // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  18. }
  19. }
  20.  
  21. void loop () {
  22. DateTime now = rtc.now();
  23.  
  24. Serial.print(now.year(), DEC);
  25. Serial.print('/');
  26. Serial.print(now.month(), DEC);
  27. Serial.print('/');
  28. Serial.print(now.day(), 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.println();
  36.  
  37. Serial.print(" since midnight 1/1/1970 = ");
  38. Serial.print(now.unixtime());
  39. Serial.print("s = ");
  40. Serial.print(now.unixtime() / 86400L);
  41. Serial.println("d");
  42.  
  43. // calculate a date which is 7 days and 30 seconds into the future
  44. DateTime future (now.unixtime() + 7 * 86400L + 30);
  45.  
  46. Serial.print(" now + 7d + 30s: ");
  47. Serial.print(future.year(), DEC);
  48. Serial.print('/');
  49. Serial.print(future.month(), DEC);
  50. Serial.print('/');
  51. Serial.print(future.day(), DEC);
  52. Serial.print(' ');
  53. Serial.print(future.hour(), DEC);
  54. Serial.print(':');
  55. Serial.print(future.minute(), DEC);
  56. Serial.print(':');
  57. Serial.print(future.second(), DEC);
  58. Serial.println();
  59.  
  60. Serial.println();
  61. delay(3000);
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement