Daily silent alarm sketch - alarm not activating as expected

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.

  volatile int alarmState = 0;

use Alarm.delay() instead of delay().

Thanks. Unfortunately nothing changes after replacing int alarmState = 0; with volatile int alarmState = 0;. The value remains at zero.

I replaced all instances of delay() with Alarm.delay() and the alarm LED did flash once but then turned off and stayed off. Serial monitor reports only 0 for alarmState. Thanks anyway.

Edit: if I change if (digitalRead(buttonPin) == LOW) to if (digitalRead(buttonPin) == 1) then I think it works as expected, although I can't be entirely sure.

Edit: if I change if (digitalRead(buttonPin) == LOW) to if (digitalRead(buttonPin) == 1) then I think it works as expected, although I can't be entirely sure.

It depends on how the button is wired.

The easiest(and most think best) way wire the button is to place the pin in INPUT_PULLUP mode which connects it internally to 5V through 30-50K ohms. Wire to legs which are diagonally across the button. Take one wire to the input pin, and the other wire to ground. The pin will read HIGH when not pressed, and LOW when pressed.

Thanks for all the help. I'm pretty sure it's working as intended now. There's a weird behaviour like if I pull out the LED that resets that alarmState to 0 but that's not really an issue so I'm okay with it.