#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "RTClib.h"
RTC_DS1307 rtc;
LiquidCrystal_I2C lcd(0x3F, 16, 2);
char weekDay[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
#define led 19
#define button 18
int buttonState=0;
String buttonValue = "ON";
void setup() {
pinMode(led, OUTPUT);
pinMode(button, INPUT_PULLUP);
Wire.begin();
rtc.begin();
Wire.beginTransmission(0x3F);
if (Wire.endTransmission())
{
lcd = LiquidCrystal_I2C(0x27, 16, 2);
}
lcd.init();
lcd.backlight();
lcd.setCursor(2,0);
lcd.print("Clock Alarm");
delay(1000);
lcd.clear();
}
void loop() {
checkAlarmOn();
DateTime now = rtc.now();
lcd.setCursor(10, 0);
lcd.println(weekDay[now.dayOfTheWeek()]);
lcd.setCursor(0, 1);
if(now.day()<10){
lcd.print("0");
}
lcd.print(now.day(), DEC);
lcd.print("/");
if(now.month()<10){
lcd.print("0");
}
lcd.print(now.month(), DEC);
lcd.print("/");
lcd.print(now.year(), DEC);
lcd.setCursor(0, 0);
if(now.hour()<10){
lcd.print("0");
}
lcd.print(String(now.hour()));
lcd.print(":");
if(now.minute()<10){
lcd.print("0");
}
lcd.print(String(now.minute()));
lcd.print(":");
if(now.second()<10){
lcd.print("0");
}
lcd.print(String(now.second()));
}
void checkAlarmOn() {
buttonState = digitalRead(button);
if(buttonState==LOW){
if(buttonValue=="ON"){
buttonValue="OFF";
digitalWrite(led, HIGH);
delay(100);
} else if(buttonValue=="OFF"){
buttonValue="ON";
digitalWrite(led, LOW);
delay(100);
}
lcd.clear();
lcd.setCursor(3,0);
lcd.print("Clock Alarm");
lcd.setCursor(6,1);
lcd.print(buttonValue);
delay(1000);
lcd.clear();
}}