Skip to content

Instantly share code, notes, and snippets.

@myabiku
Created November 23, 2015 12:05
Show Gist options
  • Save myabiku/ed9349259f976273c279 to your computer and use it in GitHub Desktop.
Save myabiku/ed9349259f976273c279 to your computer and use it in GitHub Desktop.
import processing.serial.*;
Serial myPort;
int current;
float inByte;
int[] yValues;
int w;
void setup()
{
size(640, 360);
w = width-10;
strokeWeight(3);
smooth(); // or noSmooth();
yValues = new int[w];
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
}
void draw()
{
// Here are simplifications possible
// Probably with read() http://processing.org/reference/libraries/serial/Serial_read_.html
// And get rid of this String-Stuff
String inString = myPort.readStringUntil('\n');
if (inString != null) {
inString = trim(inString);
inByte = float(inString);
current = int(map(inByte, 0, 1023, 0, height));
background(55);
for (int i = 1; i < w; i++) {
yValues[i-1] = yValues[i];
}
yValues[w-1] = current;
stroke(255, 200, 0);
line(w, current, width, current);
strokeWeight(1);
line(0, current, width, current);
strokeWeight(3);
for (int i=1; i<w; i++) {
stroke(220, 75, yValues[i]);
point(i, yValues[i]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment