Touchosc and Arduino
in
Integration and Hardware
•
3 years ago
Hello all,
I was wondering if someone could help me understand how to get a on/off value out of the message sent by the iphone app touchosc. I just need a value to run an if statement to tell the arduino to do a task. I have looked everywhere and cant find how to do this. In this code i have the output out of the touchosc of the push buttons as 1,2,3.... up to 0.
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
float v_1 = 0.0f;
float v_2 = 0.0f;
float v_3 = 0.0f;
float v_4 = 0.0f;
float v_5 = 0.0f;
float v_6 = 0.0f;
float v_7 = 0.0f;
float v_8 = 0.0f;
float v_9 = 0.0f;
float v_0 = 0.0f;
void setup() {
size(320,440);
frameRate(25);
/* start oscP5, listening for incoming messages at port 8000 */
oscP5 = new OscP5(this,8000);
}
void oscEvent(OscMessage theOscMessage) {
String addr = theOscMessage.addrPattern();
float val = theOscMessage.get(0).floatValue();
if(addr.equals("1")) { v_1 = val; }
else if(addr.equals("2")) { v_2 = val; }
else if(addr.equals("3")) { v_3 = val; }
else if(addr.equals("4")) { v_4 = val; }
else if(addr.equals("5")) { v_5 = val; }
else if(addr.equals("6")) { v_6 = val; }
else if(addr.equals("7")) { v_7 = val; }
else if(addr.equals("8")) { v_8 = val; }
else if(addr.equals("9")) { v_9 = val; }
else if(addr.equals("0")) { v_0 = val; }
}
void draw() {
background(0);
print(v_1);
if(v_1 == 1.0){
arduinoPort.write("true"); }
if(v_2 == 1.0f){
arduinoPort.write("true"); }
if(v_3 == 1.0f){
arduinoPort.write("true"); }
if(v_4 == 1.0f){
arduinoPort.write("true"); }
}
If anyone could just point me in the right direction I would be so happy.
Thanks
Ted
2