int inpin1=3;
int inpin2=4;
int inpin3=5;
int inpin4=6;
int inpin5=7;
int buttonState1 = 0; // variable for reading the pushbutton status
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState5 = 0;
void setup() {
pinMode(inpin1, INPUT);
pinMode(inpin2, INPUT);
pinMode(inpin3, INPUT);
pinMode(inpin4, INPUT);
pinMode(inpin5, INPUT);
}
void loop() {
buttonState1 = digitalRead(inpin1);
buttonState2 = digitalRead(inpin2);
buttonState3 = digitalRead(inpin3);
buttonState4 = digitalRead(inpin4);
buttonState5 = digitalRead(inpin5);
if (buttonState1 == HIGH) tone(8, 524,4);
else if (buttonState2 == HIGH) tone(8, 588,4);
else if (buttonState3 == HIGH) tone(8, 660,4);
else if (buttonState4 == HIGH) tone(8, 698,4);
else if (buttonState5 == HIGH) tone(8, 784,4);
else {
noTone(8);
}
}
沒有留言:
張貼留言