Eye-Popping Pumpkin Processing/Arduino
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
//-----------------------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-------------------------------- |
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
//----------------------------------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------------------------------------ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment