會隨著轉動的幅度而有不同的表現!!
程式碼
#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);
}
照片
影片
06 LIGHT THEREMIN
會依照感光而改變發出的聲音!!
程式碼
int sensorValue;
int sensorLow=1023;
int sensorHigh=0;
const int ledPin=13;
void setup(){
pinMode(ledPin,OUTPUT);
digitalWrite(ledPin,HIGH);
while(millis()<5000){
sensorValue=analogRead(A0);
if(sensorValue>sensorHigh){
sensorHigh=sensorValue;
}
if(sensorValue<sensorLow){
sensorLow=sensorValue;
}
}
digitalWrite(ledPin,LOW);
}
void loop(){
sensorValue=analogRead(A0);
int pitch=map(sensorValue,sensorLow,sensorHigh,50,4000);
tone(8,pitch,20);
delay(10);
}
照片
影片
07 KEYBOARD INSTRUMENT
會依據按下的按鈕發出不同的聲音!!
程式碼
int notes[]={262,294,330,349};
void setup()
{
Serial.begin(9600);
}
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);
}
}
按下不同按鈕 值皆不同
也會發出不同的聲音
照片
影片
沒有留言:
張貼留言