public
anonymous / pumpkinarduino.pde
Created

Eye-Popping Pumpkin Processing/Arduino

  • Download Gist
pumpkinarduino.pde
Processing
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
//-----------------------Start Arduino Code------------------------------
 
int message = 0; // This will hold one byte of the serial message
int eyesPin = 9; // What pin are the eyes connected to?
int eyes_val = LOW; // eyes_val will be HIGH or LOW
 
void setup()
{
Serial.begin(9600); //set serial to 9600 baud rate
}
 
void loop()
{
if (Serial.available() > 0)
{ // Check if there is a new message
message = Serial.read(); // Put the serial input into the message
 
if (message == 'R')
{ // If a capitol R is received...
eyes_val = HIGH; // Set eyes_val to HIGH and eyes are out
}
if (message == 'r')
{ // If a lowercase r is received...
eyes_val = LOW; // Set eyes_val to LOW and eyes are in
}
}
digitalWrite(eyesPin, eyes_val); // Write digital value to eyes
}
 
//----------------------------end Arduino code--------------------------------
pumpkinprocessing.pde
Processing
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
//----------------------------------start processing code------------------------------------
 
import oscP5.*; // Load OSC P5 library
import netP5.*; // Load net P5 library
import processing.serial.*; // Load serial library
 
Serial arduinoPort; // Set arduinoPort as serial connection
OscP5 oscP5; // Set oscP5 as OSC connection
 
float eyes_val;
 
//--- Function: setup
void setup()
{
 
oscP5 = new OscP5(this,8000); // Start oscP5, listening for incoming messages at port 8000
arduinoPort = new Serial(this, Serial.list()[0], 9600); // Set arduinoPort to 9600 baud
}
 
//--- Function: oscEventThis runs whenever there is a new OSC message
void oscEvent(OscMessage theOscMessage) {
{
String addr = theOscMessage.addrPattern();
if(addr.equals("/1/push1")) {
eyes_val = theOscMessage.get(0).floatValue();
}
}
}
 
 
//--- Function: pneumatic eyes on/off
void draw()
{
println(eyes_val);
if (eyes_val > 0.5) {
arduinoPort.write('R');//sends signal for eyes out
delay(200);
}
else {
arduinoPort.write('r');//sends signal for eyes in
}
 
}
 
//----------------------------------end processing code------------------------------------

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.