Freeze command

Hello again!
Currently working on a project where when a door is opened a beeper is turned on. I use a door sensor for this.
I attach the code below. The problem about it is that when i close the door the beeper stops beeping.
Any ideas on how i can make the beeper continue to beep for example 30 minutes and then it stops by itself

#include <JC_Button.h>
// pin assignments
const byte DOORSENSOR_PIN(2); //
const byte RELAY_PIN(3); //
Button myBtn(DOORSENSOR_PIN);
const unsigned long LONG_PRESS(300); //
void setup() {
myBtn.begin();
pinMode(RELAY_PIN, OUTPUT);
}
void loop() {
digitalWrite(RELAY_PIN, LOW);
myBtn.read();
if (myBtn.pressedFor(LONG_PRESS)) {

digitalWrite(RELAY_PIN, HIGH);
delay(100);

}
}

Well, how would you do it? Figure that out, then translate to code.

If the beeper is on and the current time minus the start time is more than 30 minutes
{ turn off the beeper, set the start time to now }
else
if the door opening is detected, set the start time to now and turn the beeper on

You will need millis() to track time, a uint32_t variable to store the start time, and a bool variable to keep track of the beeper state.

What is the purpose of the 100ms delay in your loop()?

const unsigned long LONG_PRESS(300);

did you mean
const unsigned long LONG_PRESS = 300; ?

aarg:

const unsigned long LONG_PRESS(300);

did you mean
const unsigned long LONG_PRESS = 300; ?

Same thing.