Processing, TouchOSC, iPad
I’ve recently started to play with TouchOSC on the iPad and Processing. I’ve written a small processing program that will track the output from the XY Pad Module on the iPad and plot it on the desktop application over a WiFi network.
TouchOSC Setup
These are what the settings on your iOS device should look like. This will work with the iPad and iPhone but the example in this post is on the iPad.
Video Demo
Demo XY Pad - TouchOSC, iPad, Processing from Curt Walker on Vimeo.
Resources
TouchOSC Processing
Processing Code:
import processing.serial.*;
import oscP5.*;
import netP5.*;
OscP5 oscP5;
float x = 0.0f;
float y = 0.0f;
void setup()
{
size(835, 610);
frameRate(25);
oscP5 = new OscP5(this, 8000);
}
void oscEvent(OscMessage theOscMessage)
{
String addr = theOscMessage.addrPattern();
float y_val = theOscMessage.get(0).floatValue();
float x_val = theOscMessage.get(1).floatValue();
if (addr.equals("/1/xy1")) { x = x_val; y = y_val; }
println("Co-ords: " + theOscMessage.get(1).floatValue() + theOscMessage.get(0).floatValue());
}
void draw()
{
background(0);
smooth();
fill(0);
strokeWeight(3);
stroke(255,255,0);
//inner rectangle
rect(1, 1, 832,544);
fill(255,255,0);
stroke(255,255,0);
strokeWeight(1);
//verticle line
line(0, y*545, 835, y*545);
//horizontal line
line(x*835,0,x*835,545);
fill(255,255,0);
stroke(255,255,0);
//stats
fill(50,50,50);
stroke(200,200,200);
rect(1,559,834,50);
fill(255);
text("y " + y*545, 445, 590);
text(" , " , 535, 590);
text("x " + x*835, 555, 590);
//Direction
text("Direction: ", 650 ,590);
if(x*835 <= 417.5){ text("Left", 720, 590); }
else { text("Right", 720, 590); }
}