Created
April 26, 2012 22:00
-
-
Save adenine/2503536 to your computer and use it in GitHub Desktop.
Quick Maker sketch
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
import com.rockwellgroup.lab.processingecs.*; // import the processingECS library | |
ProcessingECS pECS; // create a new object - see docs at http://www.ecsTBD.com for more info | |
/** | |
* Maker Faire building sketch | |
* This controls a set of 4 window outputs and reads from 4 inputs | |
*/ | |
boolean swapColor = false; | |
boolean[] outputs = new boolean[4]; | |
void setup() { | |
pECS = new ProcessingECS( "building", this ); | |
size(600,300); | |
} | |
void draw() { | |
for(int i=0; i<outputs.length; i++) { | |
if (outputs[i] == true) { | |
fill(255); | |
} else { | |
fill(0); | |
} | |
ellipse(100+(100*i), 50,80,80); | |
} | |
} | |
// This listens and sends the messages out when inputs are triggered | |
void receivedArduinoMsg( String _input ) { | |
if( _input.equals( "input1" ) ) { | |
pECS.sendRoute( "input1", "255" ); | |
outputs[0] = !outputs[0]; | |
println("input1"); | |
} | |
if( _input.equals( "input2" ) ) { | |
pECS.sendRoute( "input2", "255" ); | |
outputs[1] = !outputs[1]; | |
println("input2"); | |
} | |
if( _input.equals( "input3" ) ) { | |
pECS.sendRoute( "input3", "255" ); | |
outputs[2] = !outputs[2]; | |
println("input3"); | |
} | |
if( _input.equals( "input4" ) ) { | |
pECS.sendRoute( "input4", "255" ); | |
outputs[3] = !outputs[3]; | |
println("input4"); | |
} | |
} | |
// This controls turning the windows off and on | |
public void onRouteUpdate( String _key, String _value) { | |
if( _key.equals( "window1" ) ) { | |
println("window1"); | |
} | |
if( _key.equals( "window2" ) ) { | |
println("window2"); | |
} | |
if( _key.equals( "window3" ) ) { | |
println("window3"); | |
} | |
if( _key.equals( "window4" ) ) { | |
println("window4"); | |
} | |
} | |
void keyPressed() { | |
switch(key) { | |
case '1': | |
receivedArduinoMsg("input1"); | |
break; | |
case '2': | |
receivedArduinoMsg("input2"); | |
break; | |
case '3': | |
receivedArduinoMsg("input3"); | |
break; | |
case '4': | |
receivedArduinoMsg("input4"); | |
break; | |
} | |
} | |
void onMessage( String msg ) { | |
println( msg ); // this is the message itself in xml as sent from ECS | |
} | |
public void onOpen() { | |
println("You are now connected!"); // to show that you are communicating correctly with the ECS server | |
} | |
public void onClose() { | |
println("You have disconnected from server."); // to show that you are disconnected | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment