// Set date and time using a DS1307 RTC connected via I2C
#include <Wire.h>
#include <SPI.h> // not used here, but needed to prevent a RTClib compile error
#include "RTClib.h"
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display
RTC_DS1307 RTC; // Setup an instance of DS1307 naming it RTC
char sbuf[64];
char buf[64];
void setup() {
pinMode(7, OUTPUT);
Serial.begin(9600); // Set serial port speed
Wire.begin(); // Start the I2C
lcd.init(); // initialize the lcd
lcd.noBacklight();
RTC.begin(); // Init RTC
// RTC.adjust(DateTime(__DATE__, __TIME__)); // Time and date is expanded to date and time on your computer at compiletime
// Serial.print('Time and date set');
digitalWrite(7, LOW);
}
void loop() {
DateTime now = RTC.now();
sprintf(buf, "%02d/%02d/%02d", now.day(), now.month(), now.year()%2000);
sprintf(sbuf, "%02d:%02d:%02d", now.hour(), now.minute(), now.second());
Serial.print(buf);
Serial.print(" ");
Serial.println(sbuf);
lcd.setCursor(0, 0);
lcd.print(buf);
lcd.setCursor(0, 1);
lcd.print(sbuf);
if (now.hour() == 20 && now.minute() == 15)
digitalWrite(7, HIGH);
if (now.hour() == 20 && now.minute() == 16)
digitalWrite(7, LOW);
delay(1000);
}