DS1302

#include <Wire.h>
#include <DS1302.h>

DS1302 rtc(2, 3, 4); // RST, DAT, CLK

void setup() {
  Serial.begin(9600);
  rtc.halt(false);
  rtc.writeProtect(false);
}

void loop() {
  RTCDateTime dt = rtc.getDateTime();
  printDateTime(dt);
  delay(1000);
}

void printDateTime(const RTCDateTime& dt) {
  char buffer[20];
  sprintf(buffer, "%04d-%02d-%02d %02d:%02d:%02d",
          dt.year, dt.month, dt.day,
          dt.hour, dt.minute, dt.second);
  Serial.println(buffer);
}