Arduino + maxSonar + processing + OSC + Resolume Arena

Hi, i have one project, but i need help for make a perfect code :)

i use arduino 10k and maxsonar i need to pass with serial data ( distance ) to processing for change one controller on resolume with osc

i Have this code is ok, but not linear, many times change to different value, i search help to refine this control, i need to use ultrasound same a slider ! :)

arduino code

//Digital pin 7 for reading in the pulse width from the MaxSonar device.
//This variable is a constant because the pin will not change throughout execution of this code.
const int pwPin = 7; 
//variables needed to store values
long pulse, inches, cm;
void setup() {
  //This opens up a serial connection to shoot the results back to the PC console
void loop() {
  pinMode(pwPin, INPUT);
    //Used to read in the pulse that is being sent by the MaxSonar device.
  //Pulse Width representation with a scale factor of 147 uS per Inch.

  pulse = pulseIn(pwPin, HIGH);
  //147uS per inch
  inches = pulse/147;
  //change inches to centimetres
  cm = inches * 2.54;


Processing code

import processing.serial.*;
import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress myRemoteLocation;

Serial port;
float val;

void setup() {
  size(200, 200);

  // start oscP5, telling it to listen for incoming messages at port 8000 */
  oscP5 = new OscP5(this, 8001);

  // set the remote location to be the localhost on port 5001
  myRemoteLocation = new NetAddress("", 7000);

  port = new Serial(this, Serial.list()[8], 9600);

void draw() {
  if ( port.available() > 0) { // If data is available,
  //val =; // read it and store it in val
     float  inByte =;
    val = inByte / 1000 ;
    OscMessage myMessage = new OscMessage("/activeclip/link1/values");
    // send the message
    oscP5.send(myMessage, myRemoteLocation);


thx for all suggestion ! Mau