1.用makeruno連接搖桿產生不同頻率的聲音
2.用makeruno連接搖桿在不同位置量多少燈
3..用makeruno連接搖桿產生字母
4.用processing產生紅色不同長度的棒子
5.用processing產生紅色不同長度的棒子(更好)
⚠️注意事項:
1.記得匯入執行檔才能偵測
2.可變電阻不能直接接,還有不能放置過久
上面兩種方式可能造成冒煙或火災
1.程式碼:
void setup()
{
// put your setup code here, to run once:
pinMode(13,OUTPUT);
pinMode(8,OUTPUT);
}
void loop()
{
// put your main code here, to run repeatedly:
int now = analogRead(A0);
tone(8,now);
}
2.程式碼:
void setup()
{
// put your setup code here, to run once:
for(int i=2; i<=13;i++)
pinMode(i,OUTPUT);
}
void loop()
{
// put your main code here, to run repeatedly:
int now = analogRead(A0);
int level = now/(512/13);
for(int i=2;i<=13;i++)
{
if(i<level) digitalWrite(i, HIGH);
else digitalWrite(i, LOW);
}
}
3.程式碼:
void setup()
{
// put your setup code here, to run once:
for(int i=2;i<=13;i++)
pinMode(i,OUTPUT);
Serial.begin(9600);
}
void loop()
{
// put your main code here, to run repeatedly:
int now = analogRead(A0);
int level = now/(1024/13);
for(int i=2;i<=13;i++)
{
if(i<level) digitalWrite(i, HIGH);
else digitalWrite(i, LOW);
}
Serial.write(('A'+level));
delay(100);
}
執行結果:
import processing.serial.*;
Serial myPort;
void setup()
{
size(700,100);
myPort = new Serial (this,"COM6", 9600);
}
int level=0;
void draw()
{
background(255);
fill(255,0,0);
rect(0,0, level*50,100);
if(myPort.available()>0)
{
int now = myPort.read();
level = now- 'A';
}
}
執行結果:
5.程式碼:
import processing.serial.*;
Serial myPort;
void setup()
{
size(765,100);
myPort = new Serial (this,"COM6", 9600);
}
int level=0;
void draw()
{
background(255);
fill(255,0,0);
rect(0,0, level*3,100);
if(myPort.available()>0)
{
int now = myPort.read();
level = now;
}
}
執行結果:



沒有留言:
張貼留言