I'm trying to make a piezo buzzer "piano" with two push buttons, each making a different tone. It works with one push button, but when I try to add another, it doesn't work.
const int buttonPin1 = 2;
const int buttonPin2 = 4;
int Buzzer1 = 9;
// variables will change:
int buttonState1 = 0;
int buttonState2 = 0;
void setup() {
// initialize the piezo as output:
pinMode(Buzzer1, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
}
void loop(){
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
if (buttonState1 == HIGH) {
tone(Buzzer1,400,200);
if (buttonState2 == HIGH) {
tone(Buzzer1,450,225);
}
}
}
What's wrong?