import oscP5.*; import netP5.*; import processing.serial.*; Serial arduinoPort; OscP5 oscP5; float [] fader = new float [3]; int redLED = 0; int [] led = new int [2]; void setup() { size(480,320); noStroke(); oscP5 = new OscP5(this,8000); arduinoPort = new Serial(this, "COM16", 115200); //bluetooth //println(Serial.list()); //arduinoPort = new Serial(this, "COM4", 9600); //cable, check COM port } void oscEvent(OscMessage theOscMessage) { String addr = theOscMessage.addrPattern(); if(addr.indexOf("/1/fader") !=-1){ String list[] = split(addr,'/'); int xfader = int(list[2].charAt(5) - 0x30); if(theOscMessage.get(0).floatValue() !=0){ fader[xfader] = theOscMessage.get(0).floatValue(); } 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. } } } void draw() { //---------------------------------Motor A if(fader[1] > 0.65){ arduinoPort.write("AF100#"); } if(fader[1] < 0.35){ arduinoPort.write("AR100#"); } //--------------------------------Motor B if(fader[2] > 0.65){ arduinoPort.write("BF100#"); } if(fader[2] < 0.35){ arduinoPort.write("BR100#"); } //----------------------------stop commands if(fader[1] < 0.65 && fader[1] > 0.35 ){ arduinoPort.write("AF0#"); } if(fader[2] < 0.65 && fader[2] > 0.35 ){ arduinoPort.write("BF0#"); } if(led[1] == 0){ // If led button 1 if off do.... arduinoPort.write("l"); // Sends the character “r” to Arduino redLED = 0; // Sets redLED color to 0, can be 0-255 } if(led[1] == 1){ // If led button 1 is ON do... arduinoPort.write("L"); // Send the character “R” to Arduino redLED = 224; // Sets redLED color to 255, can be 0-255 } fill(redLED,224,224); // Fill rectangle with whiteLED amount rect(210, 160, 50, 50); // Created an ellipse at 50 pixels from the left... }