#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
int Motor = 13;
int H = A0;
int M = A1;
int b1 = A2;
int b2 = A3;
int Hv;
int Mv;
int bv1;
int bv2;
int i;
int i2;
int l=0;
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() == Hv && now.minute() == Mv) {
Serial.print("bang");
digitalWrite(Motor, HIGH);
}
bv1 = analogRead(b1);
Serial.println(bv1);
delay(1000);
if (bv1 >= 500) {
i = i + 1;
}
else {
i = 0;
}
while (i>=5){
digitalWrite(Motor,LOW);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("alarm set ");
lcd.setCursor(0,1);
Hv = analogRead(H)/85;
Mv = analogRead(M)/17;
lcd.print(Hv);
lcd.print(":");
lcd.print(Mv);
bv1 = analogRead(b1);
Serial.println(bv1);
delay(1000);
if (bv1 >= 500) {
i2 = i2 + 1;
}
else {
i2 = 0;
}
if (i2>=5){
i=0;
i2=0;
lcd.clear();
break;
}
delay(250);
}
}