TouchOSC 2 buttons, 2 LEDs

Several months ago I came across a couple of people who had created Delta robot models and were controlling them via the accelerometer on their phones. I thought this was a neat idea and decided to build my own charming little tripod and see what I could make it do.

Today I downloaded the cool app TouchOSC for my iphone. If you don’t know what this is, it’s a rather nifty program that allows you to harness the power of your smart phone’s sensors by creating virtual buttons, sliders, and other input devices that will communicate with your arduino over your network.

I am currently building up to this project by doing smaller tasks involving the OSC app and separately the delta bot. Right now I am simply getting a feel for using the OSC editor along with processing as I’m still somewhat new to programming all together. My first success was in making a set of LEDs blink when their corresponding button was pressed on my iphone’s screen.


char message = 0; // This will hold one byte of the serial message

int led7 = 7;
int led3 = 3;

void setup() {
Serial.begin(9600); //set serial to 9600 baud rate

pinMode(led7, OUTPUT);
pinMode(led3, OUTPUT);

void loop(){
if (Serial.available() > 0) { // Check if there is a new message
message =; // Put the serial input into the message

if (message == ‘Y’){ // If a ‘Y’ is recieved
digitalWrite(led7, 255);//255 tells light to go on
digitalWrite(led3, 0);

if (message == ‘N’){ // If a N is received…
analogWrite(led7, 0); //0 tells LED to go off
analogWrite(led3, 0);
if (message == ‘S’){ // If a ‘Y’ is recieved
digitalWrite(led3, 255);//255 tells light to go on
digitalWrite(led7, 0);
if (message == ‘P’){ // If a N is received…
analogWrite(led3, 0); //0 tells LED to go off
analogWrite(led7, 0);


import oscP5.*;
import netP5.*;
import processing.serial.*;

Serial arduinoPort;
OscP5 oscP5;

float v_toggle1 = 0.0f;
float v_toggle2 = 0.0f;

void setup() {
/* start oscP5, listening for incoming messages at port 8000 */
oscP5 = new OscP5(this,8000);
arduinoPort = new Serial(this,Serial.list()[1],9600);//Serial.list()[0] this will vary depending on the communication part that is used

void oscEvent(OscMessage theOscMessage) {

String addr = theOscMessage.addrPattern();
float val = theOscMessage.get(0).floatValue();

if(addr.equals(“/1/toggle1”)) { v_toggle1 = val; }
if(addr.equals(“/1/toggle2”)) { v_toggle2 = val; }


void draw() {
//create the rectangles
stroke(255, 0, 0); // outside line in rgb code
rect(125,190,60,50);// location of the border of rectangle

fill(255, 0, 0);//color the rectangle when Touch OSC is pressed

/*if the rectangle is pressed on the TouchOSC
This is what is sent to the arudino board
if(v_toggle1 == 1.0f)
rect(130,195,50,40);//the solid rectangle made when TouchOSC is pressed
//this rectangle is smaller than the first rectangle to allow a black border
if(v_toggle2 == 1.0f)
rect(130,195,50,40);//the solid rectangle made when TouchOSC is pressed
//this rectangle is smaller than the first rectangle to allow a black border

To see the code I modified as it was originally go to:

Readers Comments (1)

  1. Good job Babe, it’s on its way to being something wonderful


Leave a comment

Your email address will not be published.


%d bloggers like this: