LED Control
Controlling an LED on the Application Board is one of the simplest things to do from Processing, making it an excellent first thing to try. The name of the LED subsystem on the board is appled - Application LED. There are 4 LEDs, numbered 0 - 3, and they have a state - whether they're on or off. The argument that comes after the address sets the value of state. So we create an OSC message in the form /subsystem/device/property argument
The code below creates a 400 x 400 pixel window. If you click it, it will toggle LED 0 on the Application Board on and off. Copy the code, paste it into Processing, and hit Run.
// Make Controller Kit - LEDControl
// Toggle the Application Board LEDs on a mouse press
// based on oscP5message by andreas schlegel
import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress makeControllerAddress;
int toggleState;
void setup()
{
size( 400, 400 );
frameRate( 25 );
// start oscP5, listening for incoming messages at port 10000
oscP5 = new OscP5( this, 10000 );
// set the address of the board we're sending to...
makeControllerAddress = new NetAddress("192.168.0.200", 10000);
toggleState = 1;
}
void draw()
{
background(0);
}
void mousePressed()
{
// create a new OSC message
OscMessage myMessage = new OscMessage("/appled/0/state");
myMessage.add( toggleState ); // add an argument to the message
oscP5.send( myMessage, makeControllerAddress ); // send the message
// toggle the state of the LED and save it for next time
if( toggleState == 1 )
toggleState = 0;
else
toggleState = 1;
}
All the real action happens in mousePressed( ) - we're sending a message to App LED 0 each time the mouse is pressed. We create a new OscMessage, with an address of /appled/0/state, and then add our argument to it using add( ). The value that we add to the message, toggleState, alternates each time between 0 and 1, so we can toggle the LED on and off by pressing the mouse. As always, make sure the address used for makeControllerAddress matches the network settings you've given your board.
Shopping Cart