Advertisement
Guest User

zebibib

a guest
Jan 24th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. // Date and time functions using a DS1307 RTC connected via I2C and Wire lib
  2. #include <Wire.h>
  3. #include "RTClib.h"
  4.  
  5. RTC_DS1307 rtc;
  6.  
  7. char daysOfTheWeek[7][12] = {"Sunday","Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
  8.  
  9. void setup () {
  10. Serial.begin(9600);
  11. if (! rtc.begin()) {
  12. Serial.println("Couldn't find RTC");
  13. while (1);
  14. }
  15. if (! rtc.isrunning()) {
  16. Serial.println("RTC is NOT running!");
  17. // following line sets the RTC to the date & time this sketch was compiled
  18. // rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  19. // This line sets the RTC with an explicit date & time, for example to set
  20. // January 21, 2014 at 3am you would call:
  21. rtc.adjust(DateTime(2016, 11, 19, 19, 45, 0)); // <----------------------SET TIME AND DATE: YYYY,MM,DD,HH,MM,SS
  22. }
  23. delay(100);
  24. }
  25.  
  26. void loop () {
  27. DateTime now = rtc.now();
  28. Serial.print(now.day(), DEC);
  29. Serial.print('/');
  30. Serial.print(now.month(), DEC);
  31. Serial.print('/');
  32. Serial.print(now.year(), DEC);
  33. Serial.print(" (");
  34. Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
  35. Serial.print(") ");
  36. Serial.print(now.hour(), DEC);
  37. Serial.print(':');
  38. Serial.print(now.minute(), DEC);
  39. Serial.print(':');
  40. Serial.print(now.second(), DEC);
  41. Serial.println();
  42.  
  43. delay(3000); //Print date and time every 3 sec
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement