#include <RTClib.h>
RTC_DS1307 rtc;
String rtc_date = "";
String rtc_time = "";
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
if(!rtc.begin()){
Serial.print("RTC Not Initialized");
while(true);
}
Serial.println("RTC Found");
}
void loop() {
// put your main code here, to run repeatedly:
DateTime DT = rtc.now();
rtc_date = get_date(DT);
Serial.println(rtc_date);
rtc_time = get_time(DT);
Serial.println(rtc_time);
delay(1000);
}
String get_date(DateTime current){
int year = current.year();
int month = current.month();
int day = current.day();
String currentDate = "Date: " + String(day) + "/" + String(month) + "/" + String(year);
return currentDate;
}
String get_time(DateTime current){
int hour = current.hour();
int minute = current.minute();
int second = current.second();
String currentTime = "Time: " + String(hour) + ":" + String(minute) + ":" + String(second);
return currentTime;
}