void setup() {
pinMode(4, OUTPUT); // Speaker pin
pinMode(7, INPUT_PULLUP); // Button connected to pin 7
pinMode(8, INPUT_PULLUP); // Button connected to pin 8
}
void loop() {
static boolean alarmPlaying = false;
if (digitalRead(7) == LOW && !alarmPlaying) {
alarmPlaying = true;
while (digitalRead(8) == HIGH) {
tone(4, 3150);
delay(500);
noTone(4);
delay(500);
}
alarmPlaying = false;
}
}