互動技術概論 Arduino 按鍵音樂
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(9, 524,4); else if (buttonState2 == HIGH) tone(9, 588,4); else if (buttonState3 == HIGH) tone(9, 660,4); else if (buttonState4 == HIGH) tone(9, 698,4); else if (buttonState5 == HIGH) tone(9, 784,4); else { noTone(9); } }
沒有留言:
張貼留言