1 changed files with 48 additions and 0 deletions
@ -0,0 +1,48 @@ |
|||||
|
import processing.serial.*; |
||||
|
String row; |
||||
|
int xpin; |
||||
|
int ypin; |
||||
|
int zpin; |
||||
|
Serial myPort; |
||||
|
|
||||
|
void setup(){ |
||||
|
String portName = Serial.list()[0]; //open COM4 port |
||||
|
myPort = new Serial(this, portName, 9600); |
||||
|
|
||||
|
size(640,360,P3D); |
||||
|
background(0); |
||||
|
lights(); |
||||
|
|
||||
|
pushMatrix(); |
||||
|
translate(130, height/2, 0); |
||||
|
rotateY(1.25); |
||||
|
rotateX(-0.4); |
||||
|
noStroke(); |
||||
|
box(100); |
||||
|
popMatrix(); |
||||
|
|
||||
|
pushMatrix(); |
||||
|
translate(500, height*0.35, -200); |
||||
|
noFill(); |
||||
|
stroke(255); |
||||
|
sphere(280); |
||||
|
popMatrix(); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void draw(){ |
||||
|
|
||||
|
if ( myPort.available() > 0){ // If data is available, |
||||
|
|
||||
|
row = myPort.readStringUntil('\n'); // read it and store it in variable |
||||
|
if (row != null){ |
||||
|
String splittedRow[] = split(row, '\t'); |
||||
|
if (splittedRow.length > 0){xpin = Integer.parseInt(splittedRow[0].trim());} |
||||
|
if (splittedRow.length > 1){ypin = Integer.parseInt(splittedRow[1].trim());} |
||||
|
if (splittedRow.length > 2){zpin = Integer.parseInt(splittedRow[2].trim());} |
||||
|
|
||||
|
println(xpin + ", " + ypin + ", " + zpin); //print it out in the console |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
Loading…
Reference in new issue