byte seconds = 0;
byte minutes = 0;
byte hours = 0 ;
String rtc_date = "";
String rtc_time = "";
#include <RTClib.h>;
RTC_DS1307 rtc;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
if (!rtc.begin()){
Serial.println("RTC not initialized");
while(true);
}
Serial.println("RTC found");
}
void loop() {
DateTime dt = rtc.now();
rtc_date = get_date(dt);
Serial.println(rtc_date);
rtc_time = get_time(dt);
Serial.println(rtc_time);
delay(1000);
}
void time_check(){
if (seconds >= 60){
seconds = 0;
minutes++;
}
if (minutes >= 60){
minutes = 0;
hours++;
}
if (hours >= 24){
hours = 0;
}
}
String get_date(DateTime current){
int year = current.year();
int month = current.month();
int day = current.day();
String current_date = "Date: "+String(day)+"/"+String(month)+"/"+String(year);
return current_date;
}
String get_time(DateTime current){
int hour = current.hour();
int minute = current.minute();
int second = current.second();
String current_time = "Time: "+String(hour)+":"+String(minute)+":"+String(second);
return current_time;
}