//www.elegoo.com
//2016.12.08
int buzzer = 12;//the pin of the active buzzer
int button = 11;
void setup()
{
pinMode(buzzer,OUTPUT);//initialize the buzzer pin as an output
pinMode(button,INPUT_PULLUP); // initialize the button
}
void loop()
{
unsigned char i;
while(digitalRead(button == HIGH))
{
//output an frequency
for(i=0;i<10;i++)
{
digitalWrite(buzzer,HIGH);
delay(1);//wait for 1ms
digitalWrite(buzzer,LOW);
delay(1);//wait for 1ms
}
//output another frequency
for(i=0;i<10;i++)
{
digitalWrite(buzzer,HIGH);
delay(2);//wait for 2ms
digitalWrite(buzzer,LOW);
delay(2);//wait for 2ms
}
}
}
I am trying to replicate an alarm clock snooze button. My basic programming logic would tell me this would work. I'm very new to arduino though. What might I change or look at differently in order to stop the buzzing once the button is pushed down.