Advertisement
username32390394054

setTimeManual

Jul 9th, 2025
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | Source Code | 0 0
  1. #include <Wire.h>
  2. #include "RTClib.h"
  3.  
  4. RTC_DS3231 rtc;
  5.  
  6. #define SET_TIME true  // Set to true only once
  7.  
  8. void setup() {
  9.   Serial.begin(9600);
  10.  
  11.   if (!rtc.begin()) {
  12.     Serial.println("Couldn't find RTC");
  13.     while (1);
  14.   }
  15.  
  16.   if (SET_TIME) {
  17.     rtc.adjust(DateTime(2025, 7, 7, 13, 9, 0));  // Set time here
  18.     Serial.println("Time set.");
  19.   }
  20.  
  21.   if (rtc.lostPower()) {
  22.     Serial.println("RTC lost power, time is probably not set.");
  23.   }
  24. }
  25.  
  26. void loop() {
  27.   DateTime now = rtc.now();
  28.  
  29.   Serial.print(now.year(), DEC);
  30.   Serial.print('/');
  31.   Serial.print(now.month(), DEC);
  32.   Serial.print('/');
  33.   Serial.print(now.day(), DEC);
  34.   Serial.print(" ");
  35.   Serial.print(now.hour(), DEC);
  36.   Serial.print(':');
  37.   Serial.print(now.minute(), DEC);
  38.   Serial.print(':');
  39.   Serial.print(now.second(), DEC);
  40.   Serial.println();
  41.  
  42.   delay(1000);
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement