I have been trying to get this to work for a few days.
What I have at the moment is TouchOSC installed on my iphone sending commands to a processing program, which in turn simplifies them and sends them off to my Arduino through serial.
This is where my problem is. The commands get there and I can print them out easily enough. They arrive correctly. Format is t11 or t10 (t for toggle control, then # for id of control changed, the last # is on or off (1 or 0).
Now when I try and break this down with if statements it never seems to work. I know the data is correct when it gets to the Arduino.
I need to test if the first char is a 't' simple if statement
if(Serial.read() == 't')
before this i test if
Serial.available()
is true then through similar if statements I test if next is the number '1' or '2' for the control id, then if number is on or off, '1' or '2'.
When I test this in Serial monitor or with real data off my phone never seems to get into the loops or will get it to one and not the other. Sometimes I can tweak it to get into all of them to switch the LED on, but then won't turn it off or vice-versa.
Can anyone please give me an example of the logic that I need to use? I have also tried using switch statements for the ID doesn't seam to make much difference.