2020/12/07
(一)MakerUno、搖桿、麵包板
1. https://makeruno.com.my/getting-started/ 下載 CH341 Driver for Windows here
2. 接線
3. Arduino
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(2,INPUT_PULLUP);
pinMode(8,OUTPUT);
}
int state=0;
void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(2)==LOW&&state==0){
state=1;
Serial.write("1");
}
if(digitalRead(2)==HIGH&&state==1){
state=0;
Serial.write("0");
}
delay(100);
}
4. Processing (注意port 的部分)
import processing.serial.*;
Serial myPort;
void setup(){
size(300,200);
myPort=new Serial(this,"COM7",9600);
}
int button=0;
void draw(){
if(myPort.available()>0){
int now=myPort.read();
println("u are reading:" +now);
if(now=='1')button=1;
else button=0;
}
if(button==1) background(255,0,0);
else background(255);
}
5. Processing (try_2) (記得要開)


沒有留言:
張貼留言