Visualizing 3D motion of lolypad adxl335 sensor
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.
 
 

45 lines
1.2 KiB

import processing.serial.*;
String row;
float xpin;
float ypin;
float zpin;
Serial myPort;
void setup(){
String portName = Serial.list()[0]; //open COM4 port
myPort = new Serial(this, portName, 9600);
size(640, 360, P3D);
noStroke();
fill(204);
}
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 = Float.parseFloat(splittedRow[0].trim());}
if (splittedRow.length > 1){ypin = Float.parseFloat(splittedRow[1].trim());}
if (splittedRow.length > 2){zpin = Float.parseFloat(splittedRow[2].trim());}
println(xpin + ", " + ypin + ", " + zpin); //print it out in the console
background(0);
lights();
//if(xpin < 360){rotateX(radians(xpin));}
//if(ypin < 360){rotateY(radians(ypin));}
//if(zpin < 360){rotateZ(radians(zpin));}
camera(xpin, ypin, zpin, width/2, height/2, 0, 0, 1, 0);
translate(width/2, height/2, 0);
stroke(255);
box(160);
}
}
}