Last active
August 29, 2015 14:08
-
-
Save shurru/a1465728a61f9b5a237e to your computer and use it in GitHub Desktop.
Le IMU code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import processing.serial.*; | |
Serial myPort; | |
float roll, pitch, yaw; | |
void setup(){ | |
size(600,600,P3D); | |
myPort= new Serial(this, Serial.list()[0], 115200); | |
smooth(); | |
frameRate(30); | |
} | |
void readSensors(){ | |
String inString = new String(myPort.readBytesUntil('\n')); | |
// println(inString); | |
if (inString != null){ | |
String[] q = splitTokens(inString, "\\\t "); | |
// println(q.length + " values found"); // Prints "4 values found" | |
roll=float(q[3]); | |
pitch=float(q[4]); | |
yaw=float(q[5]); | |
println("it works"); | |
} | |
} | |
void buildBoxShape() { | |
//box(60, 10, 40); | |
noStroke(); | |
beginShape(QUADS); | |
//Z+ (to the drawing area) | |
fill(#00ff00); | |
vertex(-30, -5, 20); | |
vertex(30, -5, 20); | |
vertex(30, 5, 20); | |
vertex(-30, 5, 20); | |
//Z- | |
fill(#0000ff); | |
vertex(-30, -5, -20); | |
vertex(30, -5, -20); | |
vertex(30, 5, -20); | |
vertex(-30, 5, -20); | |
//X- | |
fill(#ff0000); | |
vertex(-30, -5, -20); | |
vertex(-30, -5, 20); | |
vertex(-30, 5, 20); | |
vertex(-30, 5, -20); | |
//X+ | |
fill(#ffff00); | |
vertex(30, -5, -20); | |
vertex(30, -5, 20); | |
vertex(30, 5, 20); | |
vertex(30, 5, -20); | |
//Y- | |
fill(#ff00ff); | |
vertex(-30, -5, -20); | |
vertex(30, -5, -20); | |
vertex(30, -5, 20); | |
vertex(-30, -5, 20); | |
//Y+ | |
fill(#00ffff); | |
vertex(-30, 5, -20); | |
vertex(30, 5, -20); | |
vertex(30, 5, 20); | |
vertex(-30, 5, 20); | |
endShape(); | |
} | |
void drawCube() { | |
pushMatrix(); | |
translate(300, 450, 0); | |
scale(4,4,4); | |
rotateX( radians(-roll)); | |
rotateZ(radians(pitch)); | |
buildBoxShape(); | |
popMatrix(); | |
} | |
void draw(){ | |
readSensors(); | |
background(#000000); | |
fill(#ffffff); | |
pushMatrix(); | |
translate(450, 250, 0); | |
stroke(#ffffff); | |
popMatrix(); | |
drawCube(); | |
} | |
notthetup
commented
Nov 7, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment