Last active
August 29, 2015 14:11
-
-
Save extrasleepy/3269fc604e0bde755128 to your computer and use it in GitHub Desktop.
Arduino Manipulates Processing
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
// * 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