Created
March 23, 2014 12:14
-
-
Save pral2a/9722290 to your computer and use it in GitHub Desktop.
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
import processing.serial.*; | |
Serial myPort; // The serial port | |
int xPos = 1; // horizontal position of the graph | |
String valoresArduino[]; | |
void setup () { | |
size(800, 300); | |
println(Serial.list()); | |
myPort = new Serial(this, Serial.list()[5], 9600); | |
myPort.bufferUntil('\n'); | |
background(255); | |
} | |
void draw () { | |
} | |
void serialEvent (Serial myPort) { | |
String lineaArduino = myPort.readStringUntil('\n'); | |
if (lineaArduino != null) { | |
lineaArduino = trim(lineaArduino); | |
valoresArduino = split(lineaArduino, ","); | |
float valorArduinoA = float(valoresArduino[0]); | |
print(valorArduinoA); | |
println(); | |
valorArduinoA = map(valorArduinoA, 0, 100, 5, height); | |
stroke(0, 0, 255, 160); | |
line(xPos, height, xPos, height - valorArduinoA); | |
if (xPos >= width) { | |
xPos = 0; | |
background(255); | |
} | |
else { | |
xPos++; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment