import oscP5.*;
import netP5.*;
import processing.serial.*;
Serial myPort;
OscP5 oscP5;
int [] fader = new int [5];
float button0;
int [] out = new int [5];
int [] menu = new int [5];
void setup() {
oscP5 = new OscP5(this,8000);
myPort = new Serial(this, "COM13", 19200); }
void oscEvent(OscMessage theOscMessage) {
String addr = theOscMessage.addrPattern();
float val = theOscMessage.get(0).floatValue();
if(addr.equals("/1/button0")) {
button0 = val;
}
if(addr.indexOf("/1/fader") !=-1){
String list[] = split(addr,'/');
int i = int(list[2].charAt(5) - 0x30);
fader[i] = (int) val;
}
}
void draw() {
while (button0==1) {
for (int i=0; i<5; i++) {
if (fader[i] != out[i]) {
out[i] = (int) (fader[i]);
myPort.write('a');
myPort.write('d');
for (int j=0; j<5; j++) {
myPort.write(out[j]);
println(out[j]);
}
}
}
}
}
String list[] = split(addr,'/');
int i = int(list[2].charAt(5) - 0x30);
fader[i] = (int) val;
}
=> /1/fader/ should also become /2/fader, /3/fader and /4/fader. Of course I could create this part four times but I was thinking of some better solution by splitting this value. Any idea?