0% found this document useful (0 votes)
7 views1 page

rtc_code

This Arduino sketch utilizes the RTClib library to interface with a DS1307 real-time clock. It initializes the RTC, retrieves the current date and time, and prints it to the serial monitor, along with the number of seconds since the year 2000. Additionally, it calculates and displays a future date that is 7 days and 30 seconds ahead of the current time.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
0% found this document useful (0 votes)
7 views1 page

rtc_code

This Arduino sketch utilizes the RTClib library to interface with a DS1307 real-time clock. It initializes the RTC, retrieves the current date and time, and prints it to the serial monitor, along with the number of seconds since the year 2000. Additionally, it calculates and displays a future date that is 7 days and 30 seconds ahead of the current time.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 1

#include <Wire.

h>
#include <RTClib.h>

RTC_DS1307 RTC;
void setup () {
Serial.begin(9600);
Wire.begin();
RTC.begin();

// following line sets the RTC to the date & time this sketch was compiled
//RTC.adjust(DateTime(__DATE__, __TIME__));

}
void loop () {
DateTime now = RTC.now();
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
Serial.print(" since 2000 = ");
Serial.print(now.get());
Serial.print("s = ");
Serial.print(now.get() / 86400L);
Serial.println("d");
// calculate a date which is 7 days and 30 seconds into the future
DateTime future (now.get() + 7 * 86400L + 30);
Serial.print(" now + 7d + 30s: ");
Serial.print(future.year(), DEC);
Serial.print('/');
Serial.print(future.month(), DEC);
Serial.print('/');
Serial.print(future.day(), DEC);
Serial.print(' ');
Serial.print(future.hour(), DEC);
Serial.print(':');
Serial.print(future.minute(), DEC);
Serial.print(':');
Serial.print(future.second(), DEC);
Serial.println();
Serial.println();
delay(3000);
}

You might also like