// This file was originally created by Joel_E_B (https://www.sparkfun.com/tutorials/152) // and modified later by Adrià M Cassorla 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 [] led = new int [50]; // Array allows us to add more toggle buttons in TouchOSC int [] lastState = new int [50]; void setup() { size(100, 100); // 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 if (addr.indexOf("/led") !=-1) { // Filters out any toggle buttons int tens = int((addr.charAt(4) )) - 0x30; // returns the ASCII number so convert into a real number by subtracting 0x30 int uni = int((addr.charAt(5) )) - 0x30; // returns the ASCII number so convert into a real number by subtracting 0x30 int nLED = tens*10+uni; // Sums the tens and the units led[nLED] = theOscMessage.get(0).intValue(); // Puts the brightness value into led[i] } } // Loop void draw() { // Pass through each LED for (int n=0; n<50; n++) { // if it is different, sends the value to the Arduino via Serial if (led[n] != lastState[n]) { lastState[n] = led[n]; // Stores the last value arduinoPort.write(str(n)); // Writes the LED number arduinoPort.write(','); // Separated by a comma arduinoPort.write(str(led[n])); //Writes the brightness arduinoPort.write('\n'); // End of the message } } }