/* import processing.serial.*; Serial port; int theDistance; int target= 0; float oldTime = 0; int mode = 1; int res = 0; int res1 = 0; int res2 = 0; int waitForReply = 70; int waitForReply2 = 70; int maxDist = 250; int biggerScreen = 3; int stepsize = 10;//get rid of the wobble int lastDistance = 0; int jumpsize = 0; int jumpTollerance = 100; void setup() { frameRate(30); println("Available serial ports:"); println(Serial.list()); port = new Serial(this, Serial.list()[1], 19200, 'N', 8, 2.0); } */ We have then calculate the next data, and drawn a marble like feedback to the position of the user. /* void movePointer(int temp1, int anum){ background(0); if( temp1 != 0){ target = temp1; // only update the actual target if it is new return; } // always do this ////movimento pallina al movimento dell'utente if(linePos == target) { //nothing } else if (target > linePos) { linePos = linePos + anum; //background(0); // stroke(0); ellipse(linePos * biggerScreen , 430, 30, 30); } else { linePos = linePos - anum; //background(0); // stroke(0); ellipse(linePos * biggerScreen , 430, 30, 30); // } } int getDist(){ float newTime = millis(); if( oldTime > newTime){ //dont do anything, giving time to the sensor //println("wait"); return(0); } //println("step"); switch(mode) { case 1: theDistance = 0; //ask for a reading port.write(byte(85)); port.write(byte(224)); port.write(byte(0)); port.write(byte(1)); port.write(byte(81)); oldTime = millis()+ waitForReply; mode = 2; break; case 2: while (port.available() > 0) { res = port.read(); // println(res); } port.write(byte(85)); port.write(byte(225)); port.write(byte(2)); port.write(byte(1)); oldTime = millis()+ waitForReply2; mode = 3; break; case 3: while (port.available() > 0) { res1 = port.read(); //println(res1); } port.write(byte(85)); port.write(byte(225)); port.write(byte(3)); port.write(byte(1)); oldTime = millis()+ waitForReply2; mode = 4; break; case 4: while (port.available() > 0) { res2 = port.read(); } theDistance = (res1 * 255) + res2; if(theDistance > maxDist){ theDistance = 0;//no good } else { theDistance = theDistance / stepsize; theDistance = theDistance * stepsize; /// this stops them wobberling but it also makes them step } //* jumpsize = (theDistance - lastDistance ); if (jumpsize < jumpTollerance){// looks OK lastDistance = theDistance; // goood reading so reset last distance } else { lastDistance = theDistance; // theDistance = 0; //not good } //*/ mode = 1; break; default: } return(theDistance); } */ /* void draw() { int temp1 = getDist(); movePointer(temp1, 6); } */ The largest problem arrived when we should calculate the position of the user to point out how beating to make part the video. We made Processing to write the next data from the sensor. /* println (target); */ Target is the variables of the sensor. So, reading the data that the sensor sent off to the computer, we were able to write the range of distance. For example: /* //timeline if (target > 0 && target < 40){ col1=255; col2=255; col3=255; } else { col1=165; col2=195; col3=130; } font = loadFont("LucidaSansBold32.vlw"); textFont(font, 32); fill (col1, col2, col3); text("70", 50, 490); */