#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "RTClib.h"
RTC_DS1307 rtc;
LiquidCrystal_I2C lcd(0x27, 16, 2);
char daysOfTheWeek[7][12] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
const int b = 13;
int bs = 0;
void setup ()
{
pinMode(7, OUTPUT);
Serial.begin(9600);
lcd.begin (16,2); // initialize the lcd
if (! rtc.begin())
{
lcd.print("Couldn't find RTC");
while (1);
}
if (! rtc.isrunning())
{
lcd.print("RTC is NOT running!");
}
//rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));//auto update from computer time
rtc.adjust(DateTime(2022, 11, 21, 0, 0, 0));// to set the time manually
}
void loop ()
{
bs = digitalRead(b);
if (bs == HIGH)
{
lcd.backlight();//To Power ON the back light
digitalWrite(7,HIGH);
DateTime now = rtc.now();
lcd.setCursor(1, 0);
lcd.print("LED ON SELAMA");
lcd.setCursor(5, 1);
lcd.print(now.hour());
lcd.print(':');
lcd.print(now.minute());
lcd.print(':');
lcd.print(now.second());
lcd.print(" ");
Serial.println("LED ON SELAMA");
Serial.println(now.second(),DEC);
}
else
{
lcd.noBacklight();
lcd.clear();
digitalWrite(7,LOW);
rtc.adjust(DateTime(0, 0, 0, 0, 0, 0));
}
}