Hi. Does anyone know if it is possible to make the button in my code operate like a snooze button? Currently when I press the button it stops the buzzer which is what I had intended but it does not make the buzzer go high again after delay(60000) like I hoped it hoped it would.
I have attempted to replace the delay with millis but I must have made a mistake. Can anyone help please?
#include <Wire.h> // for I2C communication
#include <LiquidCrystal_I2C.h> // for LCD
#include <RTClib.h> // for RTC
#define Alarm3Pin 3
const int buttonPin = 4;
int buttonState = 0;
LiquidCrystal_I2C lcd(0x27, 16, 2); // create LCD with I2C address 0x27, 16 characters per line, 2 lines
RTC_DS3231 rtc; // create rtc for the DS3231 RTC module, address is fixed at 0x68
char daysOfTheWeek[7][12] = {
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
};
void setup()
{
pinMode(Alarm3Pin,OUTPUT);
pinMode(buttonPin, INPUT);
Serial.begin(9600);
Serial.println("Initialize rtc");;
while (!Serial) ; // wait for Arduino Serial Monitor
lcd.init(); // initialize lcd
lcd.backlight(); // switch-on lcd backlight
lcd.clear(); // clear LCD display
rtc.begin(); // initialize rtc
//rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
void loop()
{
DateTime now = rtc.now();
if (now.hour() == 20 && now.minute() == 58 && now.second()==00)
{
digitalWrite(Alarm3Pin,HIGH);
delay(60000);
digitalWrite(Alarm3Pin,LOW);
}
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH)
{
// turn Alarm3Pin off:
digitalWrite(Alarm3Pin, LOW);
delay(60000);
digitalWrite(Alarm3Pin,HIGH);
delay(60000);
digitalWrite(Alarm3Pin, LOW);
}
if (!rtc.begin()) lcd.print("error");
if (now.day() < 10) lcd.print("0");
lcd.print(now.day(), DEC);
Serial.print(now.day(), DEC);
lcd.print('/');
Serial.print('/');
if (now.month() < 10) lcd.print("0");
if (now.month() < 10) Serial.print("0");
lcd.print(now.month(), DEC);
Serial.print(now.month(), DEC);
lcd.print('/');
Serial.print('/');
lcd.print(now.year(), DEC);
Serial.print(now.year(), DEC);
lcd.print(" (");
Serial.print(" (");
lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
lcd.print(") ");
Serial.print(") ");
if (now.hour() < 10) lcd.print("0");
lcd.print(now.hour(), DEC);
Serial.print(now.hour(), DEC);
lcd.print(':');
Serial.print(':');
if (now.minute() < 10) lcd.print("0");
lcd.print(now.minute(), DEC);
Serial.print(now.minute(), DEC);
lcd.print(':');
Serial.print(':');
if (now.second() < 10) lcd.print("0");
lcd.println(now.second(), DEC);
Serial.println(now.second(), DEC);
delay(1000); // delay 1 seconds
lcd.clear();
lcd.setCursor(0, 0);
}