Adding timer after alarm is triggered to security system. I've been tried to add a non-blocking delay for when the sensor is triggered, so that I can put in the password to prevent alarm from going off

if (alarmActivated == true){
currentDistance = getDistance() + 10;
if ( currentDistance < initialDistance) {
tone(buzzer,1000);
lcd.clear();
enterPassword();

    }
  }
}

void enterPassword() {
int k=5;
tempPassword = “”;
activated = true;
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" *** ALARM *** “);
lcd.setCursor(0,1);
lcd.print(“Pass>”);
while(activated) {
keypressed = myKeypad.getKey();
if (keypressed != NO_KEY){
if (keypressed == ‘0’ || keypressed == ‘1’ || keypressed == ‘2’ || keypressed == ‘3’ ||
keypressed == ‘4’ || keypressed == ‘5’ || keypressed == ‘6’ || keypressed == ‘7’ ||
keypressed == ‘8’ || keypressed == ‘9’ ) {
tempPassword += keypressed;
lcd.setCursor(k,1);
lcd.print(”");
k++;
}
}
if (k > 9 || keypressed == ‘#’) {
tempPassword = “”;
k=5;
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" *** ALARM *** ");
lcd.setCursor(0,1);
lcd.print(“Pass>”);
}
if ( keypressed == '
’) {
if ( tempPassword == password ) {
activated = false;
alarmActivated = false;
noTone(buzzer);
screenOffMsg = 0;
}
else if (tempPassword != password) {
lcd.setCursor(0,1);
lcd.print(“Wrong! Try Again”);
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" *** ALARM *** ");
lcd.setCursor(0,1);
lcd.print(“Pass>”);
}
}
}
}

2 posts were merged into an existing topic: Adding timer after alarm is triggered to security system. I’ve been tried to add a non-blocking delay for when the sensor is triggered, so that I can put in the password to prevent alarm from going off. Thank you