Skip to content

Instantly share code, notes, and snippets.

@michaelsarduino
Created September 10, 2015 20:19
Show Gist options
  • Save michaelsarduino/a4d6050c9b4cea35d274 to your computer and use it in GitHub Desktop.
Save michaelsarduino/a4d6050c9b4cea35d274 to your computer and use it in GitHub Desktop.
import processing.serial.*;
Serial arduino;
int xPos = 1;
void setup () {
size(500, 300);
arduino = new Serial(this, Serial.list()[0], 9600);
arduino.bufferUntil('\n');
background(0, 0, 0);
}
void draw () {
//keine sich wiederholende Aktionen
}
void serialEvent (Serial arduino) { //wird jedes mal ausgefuehrt wenn etwas ueber die serielle Verbindung empfangen wird
String value_string = arduino.readStringUntil('\n');
if (value_string != null) {
value_string = trim(value_string);
float value = float(value_string);
value = map(value, 0, 1023, 0, height);
stroke(127,34,255);
line(xPos, height, xPos, height - value);
if (xPos >= width) {
xPos = 0;
background(0);
}
else {
xPos++;
} //eine Position vorruecken oder neu starten
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment