Advertisement
safwan092

simple RTC code

Mar 14th, 2022
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include <Wire.h>
  2. #include "RTClib.h"
  3. RTC_DS3231 rtc;
  4. char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
  5.  
  6. void setup() {
  7.  
  8. // put at the end of setup function:
  9. initRTC();
  10.  
  11. }
  12.  
  13. void loop() {
  14. DateTime now = rtc.now();
  15. // 8 - 9 - 10 - 11 - 12 - 13 - 14 - 15 - 16
  16. if (now.hour() >= 8 && now.hour() <= 16) {
  17.  
  18. }
  19. else {
  20.  
  21. }
  22. }
  23.  
  24.  
  25. ////////////////////////////////////////////////
  26. void initRTC() {
  27. if (! rtc.begin()) {
  28. Serial.println("Couldn't find RTC");
  29. Serial.flush();
  30. while (1) delay(10);
  31. }
  32.  
  33. if (rtc.lostPower()) {
  34. Serial.println("RTC lost power, let's set the time!");
  35. rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  36. }
  37. }
  38. ////////////////////////////////////////////////
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement