一開始教了把圖片放進去,有更以前的寫法不太一樣
再來拉球會飛出去
接下來教可以用搖桿畫東西andiuio程式碼
void setup() {
// put your setup code here, to run once:
pinMode(2, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int x = analogRead(A0);
int y = analogRead(A1);
int sw= digitalRead(2);
Serial.write(x/4);
Serial.write(y/4);
Serial.write(sw);
delay(20);
}
接下來可以用滑桿拉球
processing程式碼
import processing.serial.*;
Serial myPort;
PVector user;//1.外面宣告,setup()及 draw()都看的到
PVector Y, v=null;//Y:彈弓, v:飛行速度
void setup(){
size(600,400);
myPort = new Serial(this, "COM3", 9600);
user = new PVector(100,300);
Y = new PVector(100,300);
}
void draw(){
background(255);
while(myPort.available()>=3){
int x= myPort.read();
int y= myPort.read();
int sw= myPort.read();
user.x = 100+x-128;
user.y = 100+y-128;
}
textSize(40);
fill(255,0,0); text("Y", Y.x, Y.y);
fill(255);ellipse(user.x, user.y,20,20);//3.用他的值
if(v!=null) {
user.add(v);
v.y+=0.98;
}
}





沒有留言:
張貼留言