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
and here's my code ![]()
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);
}