#include <RTClib.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int nowHr, nowMin, nowSec;
RTC_DS3231 rtc;
int h1 = 15;
int m1 = 51;
int h2 = 15;
int m2 = 52 ;
int pin_buton1 = 8;
int stop_buton =9;
int state_stop_buton = 0;
int led1_pin = 6;
int state_led = LOW;
int pushpressed = 0;
int led2_pin = 7;
int state_led2 = LOW;
void setup()
{
Wire.begin();
//rtc.adjust(DateTime(F(DATE), F(TIME)));
rtc.adjust(DateTime(2021, 03, 27, 15, 50, 50));
//rtc.setDOW(WEDNESDAY); // Set Day-of-Week to SUNDAY
// rtc.setTime(12, 0, 0); // Set the time to 12:00:00 (24hr format)
// rtc.setDate(1, 1, 2014); // Set the date to January 1st, 2014
lcd.backlight();
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Welcome To Our");
lcd.setCursor(0, 1);
lcd.print("device");
pinMode(pin_buton1, INPUT);
pinMode(stop_buton, INPUT);
pinMode(led1_pin, OUTPUT);
pinMode(led2_pin, OUTPUT);
delay(2000);
Serial.begin(9600);
}
void loop() {
timeScreen();
first_alarm();
stopPins();
second_alarm();
stopPins2();
state_stop_buton = digitalRead(stop_buton);
}
void timeScreen() {
DateTime now = rtc.now();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Time:");
lcd.setCursor(6, 0);
lcd.print(nowHr = now.hour(), DEC);
lcd.print(":");
lcd.print(nowMin = now.minute(), DEC);
lcd.print(":");
lcd.print(nowSec = now.second(), DEC);
lcd.setCursor(0, 1);
lcd.print("Date: ");
lcd.print(now.day(), DEC);
lcd.print("/");
lcd.print(now.month(), DEC);
lcd.print("/");
lcd.print(now.year(), DEC);
delay(500);
}
void stopPins() { //function to stop buzzing when user pushes stop push button
if (state_stop_buton == 1) {
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int nowHr, nowMin, nowSec;
RTC_DS3231 rtc;
int h1 = 15;
int m1 = 51;
int h2 = 15;
int m2 = 52 ;
int pin_buton1 = 8;
int stop_buton =9;
int state_stop_buton = 0;
int led1_pin = 6;
int state_led = LOW;
int pushpressed = 0;
int led2_pin = 7;
int state_led2 = LOW;
void setup()
{
Wire.begin();
//rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
rtc.adjust(DateTime(2021, 03, 27, 15, 50, 50));
lcd.backlight();
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Welcome To Our");
lcd.setCursor(0, 1);
lcd.print("device");
pinMode(pin_buton1, INPUT);
pinMode(stop_buton, INPUT);
pinMode(led1_pin, OUTPUT);
pinMode(led2_pin, OUTPUT);
delay(2000);
Serial.begin(9600);
}
void loop() {
timeScreen();
first_alarm();
stopPins();
second_alarm();
stopPins2();
state_stop_buton = digitalRead(stop_buton);
}
void timeScreen() {
DateTime now = rtc.now();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Time:");
lcd.setCursor(6, 0);
lcd.print(nowHr = now.hour(), DEC);
lcd.print(":");
lcd.print(nowMin = now.minute(), DEC);
lcd.print(":");
lcd.print(nowSec = now.second(), DEC);
lcd.setCursor(0, 1);
lcd.print("Date: ");
lcd.print(now.day(), DEC);
lcd.print("/");
lcd.print(now.month(), DEC);
lcd.print("/");
lcd.print(now.year(), DEC);
delay(500);
}
void stopPins() {
if (state_stop_buton == 1) {
pushpressed =1;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("first message ");
lcd.setCursor(0, 1);
lcd.print("was read");
delay(1200);
lcd.clear();
}
}
void startBuzz() {
if (pushpressed == 0) {
}
}
void startBuzz() {
if (pushpressed == 0) {
if (state_led == LOW) {
state_led = HIGH;
digitalWrite(led1_pin, state_led);
}
}
}
else if (pushpressed == 1) {
else if (pushpressed == 1) {
state_led = LOW;
digitalWrite(led1_pin, state_led);
}
}
void first_alarm() {
DateTime t = rtc.now();
if (int(t.hour()) == h1 && int(t.minute()) == m1) {
}
}
void first_alarm() {
DateTime t = rtc.now();
if (int(t.hour()) == h1 && int(t.minute()) == m1) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("first ");
lcd.setCursor(0, 1);
lcd.print("text");
startBuzz();
delay(5000);
}
}
//
void stopPins2() {
if (state_stop_buton == 1) {
}
}
//
void stopPins2() {
if (state_stop_buton == 1) {
pushpressed = 1;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("second message ");
lcd.setCursor(0, 1);
lcd.print("was read ");
delay(1200);
lcd.clear();
}
}
void startBuzz2() {
if (pushpressed == 1) {
}
}
void startBuzz2() {
if (pushpressed == 1) {
if (state_led2 == LOW) {
state_led2 = HIGH;
digitalWrite(led2_pin, state_led2);
}
}
else if (pushpressed == 0 ) {
state_led2 = LOW;
digitalWrite(led2_pin, state_led2);
}
}
void second_alarm() {
DateTime t = rtc.now();
if (int(t.hour()) == h2 && int(t.minute()) == m2 ) {
}
else if (pushpressed == 0 ) {
state_led2 = LOW;
digitalWrite(led2_pin, state_led2);
}
}
void second_alarm() {
DateTime t = rtc.now();
if (int(t.hour()) == h2 && int(t.minute()) == m2 ) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("second");
lcd.setCursor(0, 1);
lcd.print("text");
startBuzz2();
delay(5000);
}
}
}
}