Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Capsense_LED_Output
//Simple Soft Circuits/Capsense Connection via Spacebrew toolkit
//by Joselyn McDonald and Nicole Messier
//first step: run StandardFirmata sketch in the Arduino IDE
//StandardFirmata sketch if dound under file>examples>firmata>StandardFirmata
//move to Processing for the remainder of this project
//Firmata makes processing now behave like the Arduino IDE
//import firmata library
//Sketch>>Import Library>>Arduino(Firmata)
import org.firmata.*;
import cc.arduino.*;
//import serial library
//Sketch>>Import Library>>serial
import processing.serial.*;
//import spaceBrew library
//Sketch>>Import Library>>spacebrew
import spacebrew.*;
//this is the server replace with ""
String server="sandbox.spacebrew.cc";
//name your project!
String name="compCraft LED";
//put a description in about your project
String description ="Makin that house light up";
//create a spacebrew object
Spacebrew sb;
//create an arduino object
Arduino arduino;
//digital pin number
int LED = 13;
void setup() {
size(600, 400);
//----------spacebrew------------------
// instantiate the sb variable
sb = new Spacebrew( this );
// add each thing you subscribe to
//syntax - sb.addSubscribe( "name", "data type" )
//note the subscriber and publisher must have the SAME
//data type to connect
sb.addSubscribe( "light up", "boolean" );
// connect to spacebrew
sb.connect(server, name, description );
//----------firmata------------------
// Prints out the available serial ports.
println(Arduino.list());
// Modify this line, by changing the "0" to the index of the serial
// port corresponding to your Arduino board (as it appears in the list
// printed by the line above).
arduino = new Arduino(this, Arduino.list()[8], 57600);
// Set the Arduino digital pin as output
arduino.pinMode(LED, Arduino.OUTPUT);
}
void draw() {
//---------checking arduino-----------------
if(mousePressed){
//if mousePressed is true, light up the LED
arduino.digitalWrite(LED, Arduino.HIGH);
//println("mousepressed");
}
else {
//if mousePressed is false, do not light up the LED
arduino.digitalWrite(LED, Arduino.LOW);
//println("mouse not pressed");
}
}
//function that revecives the data from the publisher
void onBooleanMessage( String name, boolean value ) {
//println("got bool message " + name + " : " + value);
//if the incoming value is true
if (value == true) {
//turn the LED on
arduino.digitalWrite(LED, Arduino.HIGH);
//print true if value is equal to true
println("true");
}
else {
//turn the LED off
arduino.digitalWrite(LED, Arduino.LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.