You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.1 KiB
48 lines
1.1 KiB
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
|
|
}
|
|
}
|
|
|
|
}
|
|
|