Hi @dams2007 I got your message and did this for you.
Most of my Touch OSC work was done several years in Processing 1.0. But I am in the process of upgrading this to Processing 3. I don’t have any simple programs that show how to write to the iPad, but I have written one to show you how it can be done. It uses the first page of the “simple” layout that comes with Touch OSC. I can’t seem to attach a zip file or .pde so I will have to post it in text here. The buttons at the bottom of the simple layout if you click on them will toggle their state. The sliders are not controlled in this example, but all elements on the iPad or phone are reflected on the processing screen output hope it helps.
/**
* TouchOSC
*
* Example displaying values received from
* the "Simple" layout (Page1)
* and sending back a mouse click on the toggle boxes to Touch OSC
* by Mike Cook Jan 2022
*
* About Tpuch OSC see http://hexler.net/touchosc
*
*/
import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress myRemoteLocation;
String iPadIP = "192.168.178.20"; // change this to the Local IP address of your iPad / iPhone
float v_fader1 = 0.0f;
float v_fader2 = 0.0f;
float v_fader3 = 0.0f;
float v_fader4 = 0.0f;
float v_fader5 = 0.0f;
float v_toggle[] = {0.0f, 0.0f, 0.0f, 0.0f };
String toggleAddress [] = {"/1/toggle1", "/1/toggle2", "/1/toggle3", "/1/toggle4"};
boolean needsRedraw = true;
boolean mouseHit = false;
int buttonHit = 0;
int buttonRects[][] = { {22,374,50,40}, // array of button rectangles
{97,374,50,40},
{173,374,50,40},
{249,374,50, 40 }
};
void setup() {
size(320,440);
frameRate(25);
println("OSC can take 30 seconds or so to connect");
/* start oscP5, listening for incoming messages at port 8000 */
oscP5 = new OscP5(this,8000);
// set the local IP address on the iPod to this
myRemoteLocation = new NetAddress(iPadIP, 8001); // local IP on the iPad
// in choosing a static IP address make sure it is in the same domain as the host
}
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/fader2")) { v_fader2 = val; }
else if(addr.equals("/1/fader3")) { v_fader3 = val; }
else if(addr.equals("/1/fader4")) { v_fader4 = val; }
else if(addr.equals("/1/fader5")) { v_fader5 = val; }
else if(addr.equals("/1/toggle1")) { v_toggle[0] = val; }
else if(addr.equals("/1/toggle2")) { v_toggle[1] = val; }
else if(addr.equals("/1/toggle3")) { v_toggle[2] = val; }
else if(addr.equals("/1/toggle4")) { v_toggle[3] = val; }
needsRedraw = true;
}
void draw() {
if(needsRedraw == true){
background(0);
// fader5 + toggle 1-4 outlines
fill(0);
stroke(0, 196, 168);
rect(17,21,287,55);
rect(17,369,60,50);
rect(92,369,60,50);
rect(168,369,60,50);
rect(244,369,60,50);
// toggle 1-4 fills
fill(0, 196, 168);
rect(17,21,v_fader5*287,55);
if(v_toggle[0] == 1.0f) rect(22,374,50,40);
if(v_toggle[1] == 1.0f) rect(97,374,50,40);
if(v_toggle[2] == 1.0f) rect(173,374,50,40);
if(v_toggle[3] == 1.0f) rect(249,374,50,40);
// fader 1-4 outlines
fill(0);
stroke(255, 237, 0);
rect(17,95,60,255);
rect(92,95,60,255);
rect(168,95,60,255);
rect(244,95,60,255);
// fader 1-4 fills
fill(255, 237, 0);
rect(17,95 + 255 - v_fader1*255,60,v_fader1*255);
rect(92,95 + 255 - v_fader2*255,60,v_fader2*255);
rect(168,95 + 255 - v_fader3*255,60,v_fader3*255);
rect(244,95 + 255 - v_fader4*255,60,v_fader4*255);
needsRedraw = false;
}
}
void updateiPad(int button){// update the iPad
OscMessage myMessage = new OscMessage(toggleAddress[button]);
myMessage.add(v_toggle[button]);
//println("message is ", myMessage);
oscP5.send(myMessage, myRemoteLocation);
bufDelay(4); // make sure we don't do thing too fast
}
void bufDelay(long pause){
pause = pause + millis();
while(pause > millis()) { } // do nothing
}
void mousePressed() {
int x,y;
x = mouseX;
y = mouseY;
//println("Mouse down at"+x+" "+y);
buttonHit = findRect(x, y, 4);
if(buttonHit != -1) {
mouseHit= true;
noStroke();
if(v_toggle[buttonHit] == 1.0f){
fill(0, 0, 0);
v_toggle[buttonHit] = 0.0f;
}
else {
fill(0, 196, 168);
v_toggle[buttonHit] = 1.0f;
}
rect(buttonRects[buttonHit][0], buttonRects[buttonHit][1], buttonRects[buttonHit][2], buttonRects[buttonHit][3]);
//println("hit button ",buttonHit, "value", v_toggle[buttonHit]);
needsRedraw = true;
}
}
int findRect(int x, int y, int numRects){
int recDetc = -1;
for(int i = 0; i<numRects; i++){
if( x > buttonRects[i][0] && x < (buttonRects[i][0] + buttonRects[i][2]) && y > buttonRects[i][1] && y < (buttonRects[i][1] + buttonRects[i][3])) {
recDetc = i;
}
}
return recDetc;
}
void mouseReleased() {
if(mouseHit){
mouseHit = false;
if(buttonHit != -1)updateiPad(buttonHit);
}
}