void setup() { pinMode(2, INPUT_PULLUP); Serial.begin(9600); } void loop() { 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); }
import processing.serial.*; Serial myPort; PVector user; PVector Y,v=null; void setup(){ size(600,400); myPort = new Serial(this, "COM4",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); if(v!=null) user.add(v); } void mouseDragged(){ user.x=mouseX; user.y=mouseY; } void mouseReleased(){ PVector diff = PVector.sub(Y, user); v = diff.div(10); } |
|
|
|
沒有留言:
張貼留言