I’m a noob with a fairly short sketch. I can’t actually program and am sort of figuring it out as I go by copying and pasting other people’s code. I’m trying to make a silent alarm that just flashes a light at 2100 hrs every evening and carries on until I push a button. I’m using the Time and TimeAlarms libraries to do this and when the alarm goes off it’s meant to set alarmState to 1 until I press my button but the alarm doesn’t seem to change the alarmState which stays 0 the whole time.
//This sketch triggers daily alarms at 2100 hrs.
#include <Time.h>
#include <TimeAlarms.h>
int buttonPin = 8;
int ledPin = 7;
int buttonState = 0;
int alarmState = 0;
// the setup function runs once when you press reset or power the board
void setup()
{
setTime(20,59,59,0,0,0); // set time to 20:59:59
// create the alarms
Alarm.alarmRepeat(21,0,0, LithiumAlarm); // 2100 hrs every day
// initialize ledPin as an output and buttonPin as an input
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
Serial.begin(9600); // open the serial port at 9600 bps:
}
// functions to be called when an alarm triggers:
void LithiumAlarm(){
alarmState = 1;
}
// the loop function runs over and over again forever
void loop() {
if (alarmState==1) {
digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(ledPin, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
if (digitalRead(buttonPin) == LOW) {
alarmState = 0;
}
}
Serial.print(alarmState);
delay(1000);
}
Thanks for any help.