Advertisement
SallatielFernandes

RTC-now

Jul 1st, 2022
984
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // now.pde
  2. // Prints a snapshot of the current date and time along with the UNIX time
  3. // Modified by Andy Wickert from the JeeLabs / Ladyada RTC library examples
  4. // 5/15/11
  5.  
  6. #include <Wire.h>
  7. #include <DS3231.h>
  8.  
  9. RTClib myRTC;
  10.  
  11. void setup () {
  12.     Serial.begin(57600);
  13.     Wire.begin();
  14.     delay(500);
  15.     Serial.println("Nano Ready!");
  16. }
  17.  
  18. void loop () {
  19.    
  20.     delay(1000);
  21.    
  22.     DateTime now = myRTC.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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement