#include <swRTC.h>
swRTC rtc; //create a new istance of the lib
int olds,news;
String timeD="";
int hh,mm,ss,dd,mo,yy;
void setup() {
rtc.stopRTC(); //stop the RTC
rtc.setTime(0,0,0); //set the time here
rtc.setDate(1,3,2024); //set the date here
rtc.startRTC(); //start the RTC
Serial.begin(9600); //choose the serial speed here
Serial.setTimeout(100);
Serial.println(" Time input : t 2024,3,1,12,24,30");
delay(2000);
}
void loop() {
if(Serial.available()){// 시간설정시 t 2024,3,21,11,34,50형식으로 입력(년,월,일,시,분,초)
char in=Serial.read();
if(in=='t'){
yy=Serial.parseInt();
mo=Serial.parseInt();
dd=Serial.parseInt();
hh=Serial.parseInt();
mm=Serial.parseInt();
ss=Serial.parseInt();
rtc.stopRTC();
rtc.setTime(hh,mm,ss);
rtc.setDate(dd,mo,yy);
rtc.startRTC();
Serial.println("Time Reset");
}
}
news=rtc.getSeconds();
if(news!=olds){
olds=news;
dspT();
}
}
void dspT(){
timeD = rtc.getYear();
timeD += "/";
timeD += rtc.getMonth();
timeD += "/";
timeD += rtc.getDay();
timeD += " ";
timeD += rtc.getHours();
timeD += ":";
timeD += rtc.getMinutes();
timeD += ":";
timeD += rtc.getSeconds();
Serial.println(timeD);
}