Skip to content

Instantly share code, notes, and snippets.

@extrasleepy
Last active August 29, 2015 14:11
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 extrasleepy/3269fc604e0bde755128 to your computer and use it in GitHub Desktop.
Save extrasleepy/3269fc604e0bde755128 to your computer and use it in GitHub Desktop.
Arduino Manipulates Processing
// * Simple Arduino Draw
import processing.serial.*;
Serial myPort; // Create object from Serial class
int val; // Data received from the serial port
void setup()
{
size(800, 500);
// I know that the first port in the serial list on my mac
// is always my FTDI adaptor, so I open Serial.list()[0].
// On Windows machines, this generally opens COM1.
// Open whatever port is the one you're using.
String portName = Serial.list()[7];
myPort = new Serial(this, portName, 9600);
background(0,125,100);
}
void draw()
{
if ( myPort.available() > 0) { // If data is available,
val = myPort.read(); // read it and store it in val
}
if (val == 1) { // If the serial value is 0,
ellipseMode(CENTER); //draw ellipse from center
fill(random(255),255,255,150);
ellipse(random(width), random(width), 100,100);
}
else { // If the serial value is not 0,
pushMatrix();
translate(width/2, 0);
rectMode(CENTER);
rotate(QUARTER_PI);
fill(255,255,random(255),150);
rect(random(width), random(width), 50,50);
popMatrix();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment