noideaforname
YaBB Newbies
Offline
Posts: 3
iphone to arduino
Jan 17th , 2010, 2:10pm
im trying to have my iphone running touchosc control my arduino though my laptop. i have a Rotary control on the iphone that i would like to control pin 10 on the arduino as pwm. i have no idea how to do this, any help would be great. here is the code im using. import oscP5.*; import netP5.*; import processing.serial.*; import cc.arduino.*; OscP5 oscP5; Arduino arduino; int[] values = { Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW }; float v_fader1 = 0.0f; float v_toggle1 = 0.0f; float v_toggle2 = 0.0f; float v_toggle3 = 0.0f; float v_toggle4 = 0.0f; float v_toggle5 = 0.0f; float v_toggle6 = 0.0f; float v_toggle7 = 0.0f; float v_toggle8 = 0.0f; float v_toggle9 = 0.0f; float v_toggle10 = 0.0f; float v_toggle11 = 0.0f; float v_toggle12 = 0.0f; float v_toggle13 = 0.0f; void setup() { size(200,200); /* start oscP5, listening for incoming messages at port 8000 */ oscP5 = new OscP5(this,8000); println(Arduino.list()); arduino = new Arduino(this, Arduino.list()[1], 57600); for (int i = 2; i <= 13; i++) arduino.pinMode(i, Arduino.OUTPUT); } void oscEvent(OscMessage theOscMessage) { String addr = theOscMessage.addrPattern(); float val = theOscMessage.get(0).floatValue(); if(addr.equals("/1/fader1")) { v_fader1 = val; } else if(addr.equals("/1/toggle1")) { v_toggle1 = val; } else if(addr.equals("/1/toggle2")) { v_toggle2 = val; } else if(addr.equals("/1/toggle3")) { v_toggle3 = val; } else if(addr.equals("/1/toggle4")) { v_toggle4 = val; } else if(addr.equals("/1/toggle5")) { v_toggle5 = val; } else if(addr.equals("/1/toggle6")) { v_toggle6 = val; } else if(addr.equals("/1/toggle7")) { v_toggle7 = val; } else if(addr.equals("/1/toggle8")) { v_toggle8 = val; } else if(addr.equals("/1/toggle9")) { v_toggle9 = val; } else if(addr.equals("/1/toggle10")) { v_toggle10 = val; } else if(addr.equals("/1/toggle11")) { v_toggle11 = val; } else if(addr.equals("/1/toggle12")) { v_toggle12 = val; } } void draw() { // all new. controls arduino if(v_toggle1 == 1.0f) arduino.digitalWrite(2, Arduino.HIGH); values[2] = Arduino.HIGH; if(v_toggle1 < 1.0f) arduino.digitalWrite(2, Arduino.LOW); values[2] = Arduino.LOW; if(v_toggle2 == 1.0f) arduino.digitalWrite(3, Arduino.HIGH); values[3] = Arduino.HIGH; if(v_toggle2 < 1.0f) arduino.digitalWrite(3, Arduino.LOW); values[3] = Arduino.LOW; if(v_toggle3 == 1.0f) arduino.digitalWrite(4, Arduino.HIGH); values[4] = Arduino.HIGH; if(v_toggle3 < 1.0f) arduino.digitalWrite(4, Arduino.LOW); values[4] = Arduino.LOW; if(v_toggle4 == 1.0f) arduino.digitalWrite(5, Arduino.HIGH); values[5] = Arduino.HIGH; if(v_toggle4 < 1.0f) arduino.digitalWrite(5, Arduino.LOW); values[5] = Arduino.LOW; if(v_toggle5 == 1.0f) arduino.digitalWrite(6, Arduino.HIGH); values[6] = Arduino.HIGH; if(v_toggle5 < 1.0f) arduino.digitalWrite(6, Arduino.LOW); values[6] = Arduino.LOW; if(v_toggle6 == 1.0f) arduino.digitalWrite(7, Arduino.HIGH); values[7] = Arduino.HIGH; if(v_toggle6 < 1.0f) arduino.digitalWrite(7, Arduino.LOW); values[7] = Arduino.LOW; if(v_toggle7 == 1.0f) arduino.digitalWrite(8, Arduino.HIGH); values[8] = Arduino.HIGH; if(v_toggle7 < 1.0f) arduino.digitalWrite(8, Arduino.LOW); values[8] = Arduino.LOW; if(v_toggle8 == 1.0f) arduino.digitalWrite(9, Arduino.HIGH); values[9] = Arduino.HIGH; if(v_toggle8 < 1.0f) arduino.digitalWrite(9, Arduino.LOW); values[9] = Arduino.LOW; if(v_toggle9 == 1.0f) arduino.digitalWrite(10, Arduino.HIGH); values[10] = Arduino.HIGH; if(v_toggle9 < 1.0f) arduino.digitalWrite(10, Arduino.LOW); values[10] = Arduino.LOW; if(v_toggle10 == 1.0f) arduino.digitalWrite(11, Arduino.HIGH); values[11] = Arduino.HIGH; if(v_toggle10 < 1.0f) arduino.digitalWrite(11, Arduino.LOW); values[11] = Arduino.LOW; if(v_toggle11 == 1.0f) arduino.digitalWrite(12, Arduino.HIGH); values[12] = Arduino.HIGH; if(v_toggle11 < 1.0f) arduino.digitalWrite(12, Arduino.LOW); values[12] = Arduino.LOW; if(v_toggle12 == 1.0f) arduino.digitalWrite(13, Arduino.HIGH); values[13] = Arduino.HIGH; if(v_toggle12 < 1.0f) arduino.digitalWrite(13, Arduino.LOW); values[13] = Arduino.LOW; }