int LED = 8;
int Speaker = 6;
int Button = 3;
unsigned long WaitDelay = 2000;
unsigned long BlinkDelay = 300;
bool alarm = false;
void setup()
{
pinMode(LED, OUTPUT);
pinMode(Button, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(Button), mute, FALLING);
}
void loop()
{
delay( WaitDelay );
do
{
setStatus();
delay( BlinkDelay );
setStatus();
delay( BlinkDelay );
}
while(digitalRead(Button) == HIGH);
}
void setStatus()
{
alarm = !alarm;
int status = alarm ? HIGH : LOW;
int freq = alarm ? 500 : 800;
digitalWrite( LED, status );
tone( 6, freq, BlinkDelay );
}
void mute()
{
alarm = false;
digitalWrite( LED, LOW );
noTone( Speaker );
}