硬體軟體概念
發出Do Mi So
程式碼:
#define Do 523
#define Mi 659
#define So 784
void setup() {
// put your setup code here, to run once:
pinMode(8, OUTPUT);
tone(8,Do);//不給長度,一直發音
delay(1000);//等一秒
tone(8,Mi);//換另一個聲音
delay(1000);
tone(8,So);//再換另一個聲音
delay(1000);
noTone(8);//靜音
}
void loop() {
// put your main code here, to run repeatedly:
}
加入Button互動
1.setup()加pinMode(2, INPUT_PULLUP);
2.loop()加if(digitalRead(2)==LOW) tone(8,Mi,100);
#define Do 523
#define Mi 659
#define So 784
void setup() {
// put your setup code here, to run once:
pinMode(2, INPUT_PULLUP);
pinMode(8, OUTPUT);
tone(8,Do);//不給長度,一直發音
delay(1000);//等一秒
tone(8,Mi);//換另一個聲音
delay(1000);
tone(8,So);//再換另一個聲音
delay(1000);
noTone(8);//靜音
}
void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(2)==LOW) tone(8,Mi,100);
}
用processing傳1給Arduino
程式碼:
import processing.serial.*;
Serial myPort;
void setup(){
size(200,200);
myPort = new Serial(this,"COM5",9600);
}
void draw(){
}
void mousePressed(){
myPort.write("1");
}
用processing傳1,3,5給Arduino
程式碼:
import processing.serial.*;
Serial myPort;
void setup(){
size(200,200);
myPort = new Serial(this,"COM5",9600);
}
void draw(){
}
void keyPressed(){
if(key=='1') myPort.write("1");
if(key=='3') myPort.write("3");
if(key=='5') myPort.write("5");
}
void mousePressed(){
myPort.write("1");
}




沒有留言:
張貼留言