Skip to content

Instantly share code, notes, and snippets.

@bitchwhocodes
Created July 24, 2014 22:39
Show Gist options
  • Save bitchwhocodes/3b9a0ca4838aee560a10 to your computer and use it in GitHub Desktop.
Save bitchwhocodes/3b9a0ca4838aee560a10 to your computer and use it in GitHub Desktop.
SpacebrewProcessingSketch
import spacebrew.*;
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
String server = "ws://localhost:9000";
String name = "Bitchwhocodes_" + floor(random(1000));
String description = "Testing Unity to Arduino";
int bright = 0;
int count =0;
Spacebrew spacebrewConnection; // Spacebrew connection object
void setup() {
size(400, 200);
// instantiate the spacebrew object
spacebrewConnection = new Spacebrew( this );
// add each thing you publish to
spacebrewConnection.addPublish( "button_pressed", "string",true );
spacebrewConnection.addSubscribe( "button_pressed","string" );
// connect to spacebrew
spacebrewConnection.connect(server, name, description );
arduino = new Arduino(this, Arduino.list()[0], 57600);
arduino.pinMode(12, Arduino.OUTPUT);
}
void draw() {
read=arduino.digitalRead(10);
if(read >1 ){
spacebrewConnection.sendMessage( "button_pressed","string" );
}
}
void onStringMessage( String name, String value ){
// we have gotten a message
println("got string message " + name + " : " + value);
arduino.digitalWrite(13, Arduino.HIGH);
delay(1000);
arduino.digitalWrite(13, Arduino.LOW);
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment