Skip to content

Instantly share code, notes, and snippets.

@pral2a
Created March 23, 2014 12:14
Show Gist options
  • Save pral2a/9722290 to your computer and use it in GitHub Desktop.
Save pral2a/9722290 to your computer and use it in GitHub Desktop.
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