Hello All
I am fairly new to this field so need a bit of guidance with my current project.
I have created LCD clock which displays time but now I need it to create an alarm.
I want to achieve this by inputting the alarm time into the code without the use of buttons and when the time is right a buzzer will sound.
I was hoping some of you would help with guidance of reading the data on the lcd and checking it with the alarm time so that the buzzer can sound at the right time.]
Here is my current code for the display
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#define DS1307_I2C_ADDRESS 0x68
#define I2C_ADDR 0x3F
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}
void getDateDs1307(byte *second,byte *minute,byte *hour,byte *dayOfWeek,byte *dayOfMonth,byte *month,byte *year)
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f);
*dayOfWeek = bcdToDec(Wire.read());
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());
}
void setup()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
Wire.begin();
lcd.begin(16, 2);
}
void loop()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
String s, m, d, mth, h;
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
if (second < 10) { s = "0" + String(second); } else { s = String(second); }
if (minute < 10) { m = "0" + String(minute); } else { m = String(minute); }
h = String(hour);
if (dayOfMonth < 10) { d = "0" + String(dayOfMonth); } else { d = String(dayOfMonth); }
if (month < 10) { mth = "0" + String(month); } else { mth = String(month); }
char* days[] = { "NA", "Mon", "Tue", "Wed", "Thu", "Wed", "Thu", "Fri", "Sat", "Sun"};
lcd.clear();
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
lcd.setCursor(4,0);
lcd.print(h + ":" + m + ":" + s);
lcd.setCursor(1,1);
lcd.print(String(days[dayOfWeek]) + " " + d + "/" + mth + "/20" + year);
delay(1000);
}
Any examples of code or any other guidance is much appreciated
Thank You