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 int redLED1 = 0; // redLED lets us know if the LED is on or off int redLED2 = 0; int redLED3 = 0; int redLED4 = 0; int [] led = new int [5]; // Array allows us to add more toggle buttons in TouchOSC float [] fader = new float [6]; boolean sliderNeedsRedraw = true; void setup() { size(200,50); // Processing screen size noStroke(); // We don’t want an outline or Stroke on our graphics oscP5 = new OscP5(this,8000); // Start oscP5, listening for incoming messages at port 8000 arduinoPort = new Serial(this, Serial.list()[1], 9600); // Set arduino to 9600 baud } void oscEvent(OscMessage theOscMessage) { // This runs whenever there is a new OSC message String addr = theOscMessage.addrPattern(); // Creates a string out of the OSC message println(addr); // uncomment for seeing the raw message if(addr.indexOf("/1/toggle") !=-1){ // Filters out any toggle buttons int i = int((addr.charAt(9) )) - 0x30; // returns the ASCII number so convert into a real number by subtracting 0x30 led[i] = int(theOscMessage.get(0).floatValue()); // Puts button value into led[i] // Button values can be read by using led[0], led[1], led[2], etc. } if(addr.indexOf("/1/fader") !=-1){ // one of the faders String list[] = split(addr,'/'); int xfader = int(list[2].charAt(5) - 0x30); fader[xfader] = theOscMessage.get(0).floatValue(); println(" x = "+fader[xfader]); // uncomment to see x values sliderNeedsRedraw = true; } } void draw() { background(50); // Sets the background to a dark grey, can be 0-255 if(fader[1] > 0.0){ arduinoPort.write("1"); // Send the number “1” to Arduino redLED1 = 0; } if(fader[1] > 0.2){ arduinoPort.write("2"); // Send the number “2” to Arduino redLED1 = 50; } if(fader[1] > 0.3){ arduinoPort.write("3"); // Send the number “3” to Arduino redLED1 = 75; } if(fader[1] > 0.4){ arduinoPort.write("4"); // Send the number “4” to Arduino redLED1 = 100; } if(fader[1] > 0.5){ arduinoPort.write("5"); // Send the number “5” to Arduino redLED1 = 125; } if(fader[1] > 0.6){ arduinoPort.write("6"); // Send the number “6” to Arduino redLED1 = 150; } if(fader[1] > 0.7){ arduinoPort.write("7"); // Send the number “7” to Arduino redLED1 = 175; } if(fader[1] > 0.8){ arduinoPort.write("8"); // Send the number “8” to Arduino redLED1 = 200; } if(fader[1] > .9){ arduinoPort.write("9"); // Send the number “9” to Arduino redLED1 = 225; } if(fader[1] == 1){ arduinoPort.write("10"); // Send the number “10” to Arduino redLED1 = 255; } if(led[1] == 0){ arduinoPort.write("r"); // Send the lowercase “r” to Arduino redLED1 = 0; } if(fader[2] > 0.0){ arduinoPort.write("a"); // Send the character “a” to Arduino redLED2 = 0; } if(fader[2] > 0.2){ arduinoPort.write("b"); // Send the character “b” to Arduino redLED2 = 51; } if(fader[2] > 0.3){ arduinoPort.write("c"); // Send the character “c” to Arduino redLED2 = 76; } if(fader[2] > 0.4){ arduinoPort.write("d"); // Send the character “d” to Arduino redLED2 = 102; } if(fader[2] > 0.5){ arduinoPort.write("e"); // Send the character “e” to Arduino redLED2 = 127; } if(fader[2] > 0.6){ arduinoPort.write("f"); // Send the character “f” to Arduino redLED2 = 153; } if(fader[2] > 0.7){ arduinoPort.write("g"); // Send the character “g” to Arduino redLED2 = 178; } if(fader[2] > 0.8){ arduinoPort.write("h"); // Send the character “h” to Arduino redLED2 = 204; } if(fader[2] > .9){ arduinoPort.write("i"); // Send the character “i” to Arduino redLED2 = 229; } if(fader[2] == 1){ arduinoPort.write("j"); // Send the character “j” to Arduino redLED2 = 255; } if(led[2] == 0){ arduinoPort.write("k"); // Send the character “k” to Arduino redLED2 = 0; } if(fader[3] > 0.0){ arduinoPort.write("A"); // Send the character “A” to Arduino redLED3 = 0; } if(fader[3] > 0.2){ arduinoPort.write("B"); // Send the character “B” to Arduino redLED3 = 51; } if(fader[3] > 0.3){ arduinoPort.write("C"); // Send the character “C” to Arduino redLED3 = 76; } if(fader[3] > 0.4){ arduinoPort.write("D"); // Send the character “D” to Arduino redLED3 = 102; } if(fader[3] > 0.5){ arduinoPort.write("E"); // Send the character “E” to Arduino redLED3 = 127; } if(fader[3] > 0.6){ arduinoPort.write("F"); // Send the character “F” to Arduino redLED3 = 153; } if(fader[3] > 0.7){ arduinoPort.write("G"); // Send the character “G” to Arduino redLED3 = 178; } if(fader[3] > 0.8){ arduinoPort.write("H"); // Send the character “H” to Arduino redLED3 = 204; } if(fader[3] > .9){ arduinoPort.write("I"); // Send the character “I” to Arduino redLED3 = 229; } if(fader[3] == 1){ arduinoPort.write("J"); // Send the character “J” to Arduino redLED3 = 255; } if(led[3] == 0){ arduinoPort.write("K"); // Send the character “K” to Arduino redLED3 = 0; } if(fader[4] > 0.0){ arduinoPort.write("L"); // Send the character “L” to Arduino redLED4 = 0; } if(fader[4] > 0.2){ arduinoPort.write("M"); // Send the character “M” to Arduino redLED4 = 51; } if(fader[4] > 0.3){ arduinoPort.write("N"); // Send the character “N” to Arduino redLED4 = 76; } if(fader[4] > 0.4){ arduinoPort.write("O"); // Send the character “O” to Arduino redLED4 = 102; } if(fader[4] > 0.5){ arduinoPort.write("P"); // Send the character “P” to Arduino redLED4 = 127; } if(fader[4] > 0.6){ arduinoPort.write("Q"); // Send the character “Q” to Arduino redLED4 = 153; } if(fader[4] > 0.7){ arduinoPort.write("R"); // Send the character “R” to Arduino redLED4 = 178; } if(fader[4] > 0.8){ arduinoPort.write("S"); // Send the character “S” to Arduino redLED4 = 204; } if(fader[4] > .9){ arduinoPort.write("T"); // Send the character “T” to Arduino redLED4 = 229; } if(fader[4] == 1){ arduinoPort.write("U"); // Send the character “U” to Arduino redLED4 = 255; } if(led[4] == 0){ arduinoPort.write("V"); // Send the character “V” to Arduino redLED4 = 0; } fill(redLED1,0,0); // Fill rectangle with redLED amount ellipse(25, 25, 40, 40); // Created an ellipse at 50 pixels from the left... // 50 pixels from the top and a width of 50 and height of 50 pixels fill(redLED2,0,1); ellipse(75, 25, 40, 40); fill(redLED3,0,2); ellipse(125, 25, 40, 40); fill(redLED4,0,3); ellipse(175, 25, 40, 40); }