2012年12月4日 星期二

Week12,HW11


#include "pitches.h"

const int threshold = 10;    // minimum reading of the sensors that generates a note

// notes to play, corresponding to the 3 sensors:
int notes[] = {
  NOTE_A4, NOTE_B4,NOTE_C3,NOTE_D4,NOTE_E4 };

void setup() {
 
 pinMode(3, INPUT);
 pinMode(4, INPUT);  
 pinMode(5, INPUT);
 pinMode(6, INPUT);
 pinMode(7, INPUT);
 Serial.begin(9600);
}

void loop() {
  for (int thisSensor = 3; thisSensor < 8; thisSensor++) {
    // get a sensor reading:
    int sensorReading = digitalRead(thisSensor);

    // if the sensor is pressed hard enough:
    if (digitalRead(thisSensor) ==HIGH) {
      // play the note corresponding to this sensor:
      tone(8, notes[thisSensor], 20);
      Serial.println(thisSensor, DEC);
    }else if(digitalRead(thisSensor) ==LOW){
    noTone(8);
  }
   delay(20);
   
  }
}
心得:多虧老師的指點才得以debug,不過做完之後有點得意忘形就是了 呵呵

沒有留言:

張貼留言