When ever I plug the button in for this code the speaker I am using just goes off. I have lights going off and I'm trying to get a buzzer to go off with a press of a button but for what ever reason it does not want to work
int i=0;
int timer = 100; // The higher the number, the
slower the timing.
const int button = 9;
int buttonState = 0;
void setup() {
// use a for loop to initialize each pin as an output:
for (int light = 2; light < 8; light++) {
pinMode(light, OUTPUT);
//pinMode(buzzer, OUTPUT);
pinMode(button, INPUT);
}
}
void loop() {
buttonState = digitalRead(button);
// loop from the lowest pin to the highest:
for (int light = 2; light < 8; light++) {
// turn the pin on:
digitalWrite(light, HIGH);
delay(timer);
// turn the pin off:
digitalWrite(light, LOW);
if (buttonState == HIGH){
for(i=700;i<800;i++){
tone(9,i);
delay(7);
} }else {
noTone(9);
}
}
// loop from the highest pin to the lowest:
for (int light = 7; light >= 2; light--) {
// turn the pin on:
digitalWrite(light, HIGH);
delay(timer);
// turn the pin off:
digitalWrite(light, LOW);
}
}``
Comments
Post a Comment