#include <RTClib.h>
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {
"SUN", "MON", "TUe", "WED", "THU", "FRI", "SAT"
};
int secondOld; // store "now.second"
void setup () {
Serial.begin(115200);
rtc.begin(); // returns zero if RTC not found
// set RTC to date & time sketch was compiled
// rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// set RTC manually
// rtc.adjust(DateTime(2021, 1, 21, 3, 0, 0)); // yyyy mm dd hh:mm:ss
}
void loop () {
DateTime now = rtc.now();
if (secondOld != now.second()) { // only print when seconds change
zeropad(now.year(), "/"); // format the value and add a delimeter
zeropad(now.month(), "/");
zeropad(now.day(), " (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
zeropad(now.hour(), ":");
zeropad(now.minute(), ":");
zeropad(now.second(), " ");
secondOld = now.second(); // store old "seconds"
Serial.println();
}
}
void zeropad(int value, char symbol[]) {
if (value < 10)
Serial.print("0"); // pad the units value
Serial.print(value); // print the value (year, month, day, hour, minute, second)
Serial.print(symbol); // print a delimiter symbol
}