Created
June 5, 2016 20:47
-
-
Save TURBULENTE/5100f49045cb2b8c71b904a7ebb9d459 to your computer and use it in GitHub Desktop.
bend_sensor_visualization
This file contains 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
// This code was created by Citlali Hernández for the Fab Academy program 2016. | |
// Based on Tiago Figueiredo's processing code developed for Fab Acabdemy program in 2014.( http://fabacademy.org/archives/2014/students/figueiredo.tiago/assignments/week15.html ) | |
// - - - - - - - - - - - - - - - l i b r a r i e s - - - - - - - - - - - - - - | |
import processing.serial.*; | |
// - - - - - - - - - - - - - - - v a r i a b l e s - - - - - - - - - - - - - - | |
Serial myPort; // Create object from Serial class | |
int val; // Data received from the serial port | |
int sensorData; // Data received from the serial port with 1,2,3,4 framing numbers filtered out | |
int low=0; | |
int med=0; | |
int high=0; | |
int value=0; | |
int byte1 = 0; | |
int byte2 = 0; | |
int byte3 = 0; | |
int byte4 = 0; | |
int yc; | |
float m; | |
int yy=0; | |
int angulo; | |
// - - - - - - - - - - - - - - - s e t u p - - - - - - - - - - - - - - | |
void setup() { | |
size (800, 600); | |
smooth(); | |
println(Serial.list()); | |
myPort = new Serial(this, "/dev/cu.usbserial-A8003XTx", 9600); | |
} | |
// - - - - - - - - - - - - - - - l o o p - - - - - - - - - - - - - - - | |
void draw() { | |
fill(#17FFC7); | |
rectMode(CENTER); | |
rect(200, height/2, 400, height); | |
fill(60, 0, 72); | |
rectMode(CENTER); | |
rect(600, height/2, 400, height); | |
noStroke(); | |
read_data(); | |
circle_(); | |
direction(); | |
m= map(value, 750, 1000, 350, 30); | |
//texto | |
fill(90); | |
text("value is= "+ value, 6, 13); | |
text("mapped value m is= "+ m, 6, 22); | |
} | |
void circle_(){ | |
if (m >= 150){ | |
fill(255); | |
} else{ | |
yc=height/2; | |
fill(255); | |
} | |
//eliipse | |
noStroke(); | |
ellipse(200, yc, m,m); | |
yy=yy+1; | |
} | |
void direction () { | |
if(m<=50){ | |
angulo++; | |
}else{angulo--; | |
fill(255,255,255); | |
} | |
pushMatrix(); | |
translate(600, height/2); | |
rotate(radians(angulo*0.9)); | |
fill(255); | |
ellipse(-100,100,50,50); | |
popMatrix(); | |
} | |
void read_data(){ | |
while (myPort.available() > 0) { // If data is available | |
byte1 = byte2; | |
byte2 = byte3; | |
byte3 = byte4; | |
byte4 = low; | |
low = high; | |
high = myPort.read(); | |
if ((byte1 == 1) & (byte2 == 2) & (byte3 == | |
3) & (byte4 == 4)){ // Filter out the framing numbers: 1,2,3,4 | |
value = (256*high + low); | |
println("THE VALUE IS " + value); //print to the screen | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment