Created
March 31, 2014 17:41
-
-
Save jerog1/9897872 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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