unsigned long now, lastaction = 0;
const byte buzzerPin = 11;
const byte switch1Pin = 12;
void setup() {
pinMode(switch1Pin, INPUT_PULLUP);
}
void loop() {
now = millis();
if (digitalRead(switch1Pin)==LOW){
if (lastaction == 0){
lastaction = now;
}
} else {
lastaction = 0;
noTone(buzzerPin);
}
if (lastaction>0){
if (now-lastaction>5000){
tone(buzzerPin, 494);
}
}
}