Advertisement
microrobotics

Untitled

Jul 13th, 2023
4,551
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Wire.h>
  2. #include "RTClib.h"
  3.  
  4. RTC_DS3231 rtc;
  5.  
  6. void setup() {
  7.   Serial.begin(9600);
  8.   Wire.begin();
  9.  
  10.   // Check if the DS3231 module is connected
  11.   if (!rtc.begin()) {
  12.     Serial.println("Couldn't find RTC");
  13.     while (1);
  14.   }
  15.  
  16.   // Uncomment the line below to set the time on the DS3231 module
  17.   // rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  18. }
  19.  
  20. void loop() {
  21.   DateTime now = rtc.now();
  22.  
  23.   // Print the current date and time
  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.   delay(1000);
  38. }
Tags: DS3231 RTC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement