#include "RTClib.h"
const int dataPin = 2; /* DS */
const int clockPin = 3; /* SHCP */
const int latchPin = 4; /* STCP */
RTC_DS1307 rtc;
DateTime now;
uint8_t hour, minute, second;
void setup () {
Serial.begin(115200);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(latchPin, OUTPUT);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
}
void update_time()
{
DateTime now = rtc.now();
hour = now.hour();
minute = now.minute();
second = now.second();
}
void write_time()
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, hour);
shiftOut(dataPin, clockPin, MSBFIRST, minute);
shiftOut(dataPin, clockPin, MSBFIRST, second);
digitalWrite(latchPin, HIGH);
}
void loop () {
update_time();
write_time();
}