Arduino lath delay

Hi, I am trying to make a burglar alarm panel with an Arduino, the problem i am having is for the time delay. Pin 2 is a switch, which will be the door contacts for the alarm, when opened, there is a 10 second delay before pin 13 becomes HIGH, which will be the siren. The problem i am having is, he delay can be stopped by closing the door, so it is rendered useless. I need it to continue counting down, even if the door is closed and activate pin 13, is it simple to make it latch the delay?

Thanks in advance

You can set a flag variable:

if(digitalRead(doorSwitchPin)==HIGH){
  doorWasOpened = true;
}

Then make your alarm code dependent on doorWasOpened, not the door switch state.

You could do it like this:

#define DOOR_TRIGGER_MILLIS 10000
#define DOOR_PIN 2
#define SIREN_PIN 13

unsigned long doorOpened = 0, loopMillis;

void loop()
{
  loopMillis = millis();
  if ( (digitalRead(DOOR_PIN) == HIGH) && (doorOpened == 0) ) doorOpened = loopMillis;
  if ( (doorOpened != 0) && (loopMillis - doorOpened >= DOOR_TRIGGER_MILLIS) ) digitalWrite(SIREN_PIN, HIGH);
}