controlling LED's with an iphone

hey there i am working on a project where im trying to use my iphone to toggle 3 leds with 3 different buttons using touchOSC i got the arduino code running and the leds lights by entering E,R or T into the serial so im using "processing" to code the stuff that is going to take the input from my phone and light the led, but i think its very hard to use this with my iphone is there an easier way to make this work ? and i can only get 1 button in my iphone to work but the arduino code works 100%

anyways i think this is ver hard to explain :P and here's my code :P

arduino:

int message = 0;

int ledPin1 = 8;
int redLed = 0;

int ledPin2 = 9;
int blueLed = 0;

int ledPin3 = 10;
int whiteLed = 0;

void setup() {  
  Serial.begin(9600);
  pinMode(redLed, OUTPUT);
  pinMode(blueLed, OUTPUT);
  pinMode(whiteLed, OUTPUT);
}

void loop(){
    if (Serial.available() > 0) {
      message = Serial.read();
      Serial.println(message);
      switch(message) {
        case 'T':
          blueLed = 255;
          break;
        case 't':
          blueLed = 0;
          break;
        case 'R':
          whiteLed = 255;
          break;
        case 'r':
          whiteLed = 0;
          break;
        case 'E':
          redLed = 255;
          break;
        case 'e':
          redLed = 0;
          break;
      }
 }   
analogWrite(ledPin1, redLed);
analogWrite(ledPin2, blueLed);
analogWrite(ledPin3, whiteLed);
}

processing code:

import oscP5.*;        //  Load OSC P5 library
import netP5.*;        //  Load net P5 library
import processing.serial.*;    //  Load serial library

Serial arduinoPort;        //  Set arduinoPort as serial connection
OscP5 oscP5;            //  Set oscP5 as OSC connection

int redLED = 0;        //  redLED lets us know if the LED is on or off
int [] led = new int [2];    //  Array allows us to add more toggle buttons in TouchOSC

int blueLED = 0;
int [] led1 = new int [2];

void setup() {
  size(150,100);        // Processing screen size
  noStroke();            //  We don’t want an outline or Stroke on our graphics
    oscP5 = new OscP5(this,8000);  // Start oscP5, listening for incoming messages at port 8000
   arduinoPort = new Serial(this, Serial.list()[0], 9600);    // Set arduino to 9600 baud
}

void oscEvent(OscMessage theOscMessage) {   //  This runs whenever there is a new OSC message

    String addr = theOscMessage.addrPattern();  //  Creates a string out of the OSC message
    if(addr.indexOf("/1/toggle") !=-1){   // Filters out any toggle buttons
      int i = int((addr.charAt(9) )) - 0x30;   // returns the ASCII number so convert into a real number by subtracting 0x30
      led[i]  = int(theOscMessage.get(0).floatValue());     //  Puts button value into led[i]
    // Button values can be read by using led[0], led[1], led[2], etc.
     
    String addr1 = theOscMessage.addrPattern();
    }
    if(addr.indexOf("/2/toggle") !=-1){
      int o = int((addr.charAt(9) )) - 0x30;
      led1[o] = int(theOscMessage.get(0).floatValue());
    }
}

void draw() {
 background(50);        // Sets the background to a dark grey, can be 0-255

   if(led[1] == 0){        //  If led button 1 if off do....
    arduinoPort.write("r");    // Sends the character “r” to Arduino
    redLED = 0;        // Sets redLED color to 0, can be 0-255
  }
 if(led[1] == 1){        // If led button 1 is ON do...
  arduinoPort.write("R");    // Send the character “R” to Arduino
  redLED = 255;        // Sets redLED color to 255, can be 0-255
  }
  if(led1[1] == 0) {
    arduinoPort.write("t");
    blueLED = 0;
  }
  if(led1[1] == 1) {
    arduinoPort.write("T");
  }
fill(redLED,0,0);            // Fill rectangle with redLED amount
   ellipse(100, 50, 50, 50);    // Created an ellipse at 50 pixels from the left...
                // 50 pixels from the top and a width of 50 and height of 50 pixels
fill(blueLED,0,0);
   ellipse(50, 50, 50, 50);
}
    String addr = theOscMessage.addrPattern();  //  Creates a string out of the OSC message
    String addr1 = theOscMessage.addrPattern();

You get the exact same value into two different variables? Why?

      led[i]  = int(theOscMessage.get(0).floatValue());     //  Puts button value into led[i]

Does theOscMessage really contain any floats?

// returns the ASCII number so convert into a real number by subtracting 0x30

ASCII values are as real as any other number. BS comments are useless.

      int i = int((addr.charAt(9) )) - 0x30;   
      int o = int((addr.charAt(9) )) - 0x30;

It's good that you've attempted to debug the issue by actually printing out the values of i and o.

      led[i]  = int(theOscMessage.get(0).floatValue());

What value did you actually get here?

   if(led[1] == 0){        //  If led button 1 if off do....

If you don't know what position in the array you wrote to, you certainly can not know what position to read from.

analogWrite(ledPin1, redLed);
analogWrite(ledPin2, blueLed);
analogWrite(ledPin3, whiteLed);

Its a waste to use analogWrite to turn the LED full on or full OFF. Pin 8 is not a PWM pin, so analogWrite doesn't do anything on that pin.

yea i really don't know i just wanted to start using touchOSC and teach me it so i found that code as a sample and tried modifing it :P i got 2 of them to work as i said but the 3rd won't and i think its because its not a PWM or w/e u said :P

i just wanted to start using touchOSC and teach me it

You have two choices. Change the non-PWM pin to a PWM pin, and hope it works.

Or, take this opportunity to learn something about touchOSC, Processing, and Arduino.

Your choice.

If you really want to learn, start with understanding what touchOSC is conveying to Processing. If you don't, you'll not be able to successfully expand it. You should, for instance, be able to create sliders in touchOSC, and actually change the brightness of the LED, instead of just turning it off or on. But, that requires that you know what you can do in touchOSC, and what data touchOSC makes available in Processing.

When you know what Processing is getting in the message(s), you can sent appropriate data to the Arduino. Instead of just T or t, you could send T180, for instance, to set the intensity of the LED to 180/255 of full brightness.

yea i am a php developer myself and i really don't like copy and paste :P but i am just using it to learn about processing so every time i get an error or a problem i investigate the code til i understand all the functions ;) and yes i am going to learn how to add sliders and souch after having 3 buttons work :D

i got the arduino code to light the lights in the Serial using E,R,T :P by changing to a PWM pin, but i am still going to learn touchOSC and its functions :)

thanks to everyone who replied