#include <RTClib.h>
RTC_DS1307 rtc;
String rtcdate = "";
String rtctime = "";
byte seconds = 0;
byte minutes = 0;
byte hours = 0;
void setup() {
Serial.begin(9600);
if (!rtc.begin()){
Serial.println("rtc not initialtizsed");
while (true);
}
}
void loop() {
DateTime dt = rtc.now();
rtcdate = getDate(dt);
rtctime = getTime(dt);
Serial.println(rtcdate);
Serial.println(rtctime);
delay(1000);
}
void timecheck(){
if (seconds > 59){
seconds = 0;
minutes++;
}
if (minutes > 59){
minutes = 0;
hours++;
}
if (hours > 23){
hours = 0;
seconds = 0;
minutes = 0;
}
}
String getDate(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 getTime(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;
}