2013年12月1日 星期日

WEEK13 廖中遠








int buttons[6];

int notes[]={523.25,587.33,659.26,698.46};
void setup(){
  Serial.begin(9600);
  buttons[0]=2;
}
void loop(){
  int keyVal=analogRead(A0);
  Serial.println(keyVal);
  if(keyVal==1023){
    tone(8,notes[0]);
  }
  else if(keyVal>=990&&keyVal<=1010){
    tone(8,notes[1]);
  }
   else if(keyVal>=505&&keyVal<=515){
    tone(8,notes[2]);
  }
   else if(keyVal>=5&&keyVal<=10){
    tone(8,notes[3]);
  }
  else{
    noTone(8);
  }
}






#include <Servo.h>

Servo myServo;

int const potPin=A0;
int potVal;
int angle;
void setup(){
  myServo.attach(9);

  Serial.begin(9600);
}

void loop(){
  potVal=analogRead(potPin);
  Serial.print("potVal:");
  Serial.print(potVal);

  angle=map(potVal,0,1023,0,179);
  Serial.print("angle:");
  Serial.println(angle);

  myServo.write(angle);
  delay(15);
}


沒有留言:

張貼留言