import processing.opengl.*; import oscP5.*; import netP5.*; import processing.serial.*; OscP5 oscP5; Serial arduino; float xrot = 0; float zrot = 0; float xrot_targ = 0; float zrot_targ = 0; float orientation = 0; float fader1 = 0.0f; float rotary1 = 0.0f; float eyes_val; float dampSpeed = 5; void setup() { size(400,400, OPENGL); oscP5 = new OscP5(this,8000); arduino = new Serial(this,Serial.list()[0],9600); smooth(); } void draw() { camera( 0, 0, 300, 0, 0, 0, 0.0, 1.0, 0.0 ); background(0); // Basic value smoothing if (xrot_targ > xrot) { xrot = xrot + ((xrot_targ - xrot) / dampSpeed); } else { xrot = xrot - ((xrot - xrot_targ) / dampSpeed); } if (zrot_targ > zrot) { zrot = zrot + ((zrot_targ - zrot) / dampSpeed); } else { zrot = zrot - ((zrot - zrot_targ) / dampSpeed); } // Detection for if the iPhone is upsidedown or not if (orientation < 0) { fill(255,0,0); rotateX(radians(xrot)); rotateZ(radians(zrot)); } else { fill(255,255,0); rotateX(radians(xrot*-1)); rotateZ(radians(zrot*-1)); } box(130,10,60); } void oscEvent(OscMessage theOscMessage) { String addr = theOscMessage.addrPattern(); // get the value of the control float val = theOscMessage.get(0).floatValue(); float val1 = theOscMessage.get(0).floatValue(); // if statements to assign values of OSC controls if(addr.equals("/1/fader1")) { fader1 = val; } else if(addr.equals("/1/rotary1")) { rotary1 = val; } else if(addr.equals("/1/toggle2")) { eyes_val = val1; } if(eyes_val==1.0) { if(theOscMessage.checkAddrPattern("/accxyz")==true) { xrot_targ = (theOscMessage.get(0).floatValue()*90); zrot_targ = (theOscMessage.get(1).floatValue()*90)*-1; orientation = theOscMessage.get(2).floatValue(); println(xrot_targ); // println(zrot_targ); println(eyes_val); } // print(fader1); //print(" "); //print(rotary1); //println(" "); } // control con el acelerometro if (eyes_val==1.0) { if (zrot_targ<=0&&zrot_targ<=10) { arduino.write("s"); } if (xrot_targ<=0&&xrot_targ<=10) { arduino.write("s"); } if (xrot_targ<=0&&xrot_targ<=-10) { arduino.write("s"); } if (zrot_targ<=0&&zrot_targ<=-10) { arduino.write("s"); } if (zrot_targ>=11&&zrot_targ<=30) { arduino.write("j"); } if (zrot_targ>=31&&zrot_targ<=51) { arduino.write("h"); } if (zrot_targ>=52&&zrot_targ<=73) { arduino.write("g"); } if (zrot_targ<=-11&&zrot_targ>=-30) { arduino.write("k"); } if (zrot_targ<=-31&&zrot_targ>=-51) { arduino.write("l"); } if (zrot_targ<=-52&&zrot_targ>=-73) { arduino.write("q"); } if (xrot_targ>=11&&xrot_targ<=30) { arduino.write("x"); } if (xrot_targ>=31&&xrot_targ<=51) { arduino.write("z"); } if (xrot_targ>=52&&xrot_targ<=73) { arduino.write("b"); } if (xrot_targ>=-11&&xrot_targ<=-30) { arduino.write("a"); } if (xrot_targ<=-31&&xrot_targ>=-51) { arduino.write("d"); } if (xrot_targ<=-52&&xrot_targ>=-73) { arduino.write("f"); } } if(eyes_val==0.0) { if (val==100&&val<=112) { arduino.write("f"); } if (val>=113&&val<=125) { arduino.write("d"); } if (val>=126&&val<=136) { arduino.write("a"); } if (val>=137&&val<=139) { arduino.write("s"); } if (val>=140&&val<=151) { arduino.write("x"); } if (val>=152&&val<=163) { arduino.write("z"); } if (val>=164&&val<=177) { arduino.write("b"); } if (val>=214&&val<=216) { arduino.write("s"); } if (val>=178&&val<=190) { arduino.write("q"); } if (val>=191&&val<=201) { arduino.write("l"); } if (val>=202&&val<=213) { arduino.write("k"); } if (val>=217&&val<=229) { arduino.write("j"); } if (val>=230&&val<=242) { arduino.write("h"); } if (val>=243&&val<=255) { arduino.write("g"); } } }