#include "RTClib.h" // include The libraries
#include <LiquidCrystal.h>
RTC_DS3231 rtc; //initialize the RTC
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //the pins the lcd is connected to
char daysOfTheWeek[7][12] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; //character array of the days of the week
int Motor = 13;
void setup() {
pinMode(Motor, OUTPUT);
digitalWrite(Motor, LOW);
Serial.begin(9600); //initialize the serial monitor
lcd.begin(16, 2); //define the size of the lcd
#ifndef ESP8266 //loop to check if the rtc is connected properly
while (!Serial)
;
#endif
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
Serial.println("Setting the time...");
rtc.adjust(DateTime(2003, 10, 30, 12, 00, 00));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
void loop() {
DateTime now = rtc.now(); //give the function of the current time a name
lcd.setCursor(0, 0); //set the cursor of the lcd to the top left
lcd.print(now.hour(), DEC); //print the values of the rtc
lcd.print(":");
lcd.print(now.minute(), DEC);// dec for te base 10
lcd.print(":");
lcd.print(now.second(), DEC);
lcd.setCursor(0, 1);
lcd.print(now.month(), DEC);
lcd.print("/");
lcd.print(now.day(), DEC);
lcd.print("/");
lcd.print(now.year(), DEC);
lcd.print(" ");
if (now.hour() == 12 && now.minute() == 0 && now.second() == 5) {
Serial.print("bang");
digitalWrite(Motor, HIGH);
}
delay(1000);
}