Skip to content

Instantly share code, notes, and snippets.

@squix78
Created May 28, 2016 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save squix78/cfdd85eb0204689b5f9c87cc6b151256 to your computer and use it in GitHub Desktop.
Save squix78/cfdd85eb0204689b5f9c87cc6b151256 to your computer and use it in GitHub Desktop.
import processing.serial.*;
int lf = 10; // Linefeed in ASCII
String myString = null;
Serial myPort; // The serial port
int rad = 5; // Width of the shape
void setup() {
size(1024, 768);
noStroke();
frameRate(30);
ellipseMode(RADIUS);
// List all the available serial ports
printArray(Serial.list());
// Open the port you are using at the rate you want:
myPort = new Serial(this, Serial.list()[5], 115200);
myPort.clear();
// Throw out the first reading, in case we started reading
// in the middle of a string from the sender.
myString = myPort.readStringUntil(lf);
myString = null;
}
void draw() {
background(102);
while (myPort.available() > 0) {
myString = myPort.readStringUntil(lf);
String[] list = split(myString, ',');
ellipse(float(list[0]), float(list[1]), rad, rad);
ellipse(float(list[2]), float(list[3]), rad, rad);
ellipse(float(list[4]), float(list[5]), rad, rad);
ellipse(float(list[6]), float(list[7]), rad, rad);
if (myString != null) {
println(myString);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment