#include #include #include /* Set the appropriate digital I/O pin connections */ uint8_t CE_PIN = 5; uint8_t IO_PIN = 6; uint8_t SCLK_PIN = 7; /* Create buffers */ char buf[50]; char day[10]; /* Create a DS1302 object */ DS1302 rtc(CE_PIN, IO_PIN, SCLK_PIN); void print_time() { /* Get the current time and date from the chip */ Time t = rtc.time(); /* Name the day of the week */ memset(day, 0, sizeof(day)); /* clear day buffer */ switch (t.day) { case 1: strcpy(day, "Sunday"); break; case 2: strcpy(day, "Monday"); break; case 3: strcpy(day, "Tuesday"); break; case 4: strcpy(day, "Wednesday"); break; case 5: strcpy(day, "Thursday"); break; case 6: strcpy(day, "Friday"); break; case 7: strcpy(day, "Saturday"); break; } snprintf(buf, sizeof(buf), "%s %04d-%02d-%02d %02d:%02d:%02d", day, t.yr, t.mon, t.date, t.hr, t.min, t.sec); Serial.println(buf); } void setup() { Serial.begin(9600); rtc.write_protect(false); rtc.halt(false); Time t(2020, 8, 5, 11,12,13,4); rtc.time(t);} void loop() { print_time(); delay(1000);}