2012年12月4日 星期二

Week13,HW11

(1)Demo影片


(2)程式碼
int buttonPin = 2;
int buttonPin1 = 3;
int buttonPin2 = 4;
int buttonPin3 = 5;
int buttonPin4 = 6;
int buttonState = 0;
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;

void setup() {
  pinMode(buttonPin, INPUT); 
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);
  pinMode(buttonPin4, INPUT);
}

void loop(){
  buttonState = digitalRead(buttonPin);
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3);
  buttonState4 = digitalRead(buttonPin4);
 
  if (buttonState == HIGH) {    
    tone(9,261,100); 
  }
  if (buttonState1 == HIGH) {
    tone(9,294,100);
  }
  if (buttonState2 == HIGH) {
    tone(9,329,100);
  }
  if (buttonState3 == HIGH) {
    tone(9,349,100);
  }
  if (buttonState4 == HIGH) {
    tone(9,392,100);
  }
 
}

沒有留言:

張貼留言