Skip to content

Instantly share code, notes, and snippets.

@jerog1
Created March 31, 2014 17:41
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 jerog1/9897872 to your computer and use it in GitHub Desktop.
Save jerog1/9897872 to your computer and use it in GitHub Desktop.
// Adapted from the Graphing sketch by Jeremy Nir
import processing.serial.*;
PImage img;
Serial myPort; // The serial port
int knobby = 1; // horizontal position of the graph
void setup () {
// set the window size:
size(1090, 900);
img = loadImage("etch-a-jer.png");
// List all the available serial ports
println(Serial.list());
// I know that the first port in the serial list on my mac
// is always my Arduino, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[8], 9600);
// don't generate a serialEvent() unless you get a newline character:
myPort.bufferUntil('\n');
// set inital background:
background(#555555);
}
void draw () {
}
void serialEvent (Serial myPort) {
// get the ASCII string:
String inString = myPort.readStringUntil('\n');
if (inString != null) {
// trim off any whitespace:
inString = trim(inString);
// convert to an int and map to the screen height:
float inByte = float(inString);
inByte = map(inByte, 0, 1023, 0, height);
image(img, 0, 0);
fill (#000000);
ellipse (mouseX, height-inByte ,4,4);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment