Since putting up the post I've written what I need. I'm putting it here in case it's of help to others. Basically it measures the distance between an object and an ultrasonic transducer and sends it to a Processing sketch for printout in the Processing monitor window.
/* ---------------------------------------------------------------------------
// Compute distance using ultrasonic sensor and send to PC running the following
Processing sketch based on Arduino Cookbook
import processing.serial.*;
Serial myPort; // Create object from Serial class
short portIndex = 1; // select the com port, 0 is the first port
char HEADER = 'H';
int value;
void setup()
{
String portName = Serial.list()[portIndex];
println(Serial.list());
println(" Connecting to -> " + Serial.list()[portIndex]);
myPort = new Serial(this, portName, 9600);
}
void draw()
{
if ( myPort.available() >= 3) // if at least 3 bytes are available
{
int hdr = myPort.read();
if (hdr == HEADER)
{
value = myPort.read();
println("Message received: " + char(hdr) +" "+ value );
}
}
}
*/
// following Arduino code based on NewPing sketch
#include <NewPing.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h> //for I2C bus
#define TRIGGER_PIN 3
#define ECHO_PIN 2
#define MAX_DISTANCE 100 // Maximum distance we want to ping for (in centimeters)
int dist;
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
void setup() {
lcd.begin(16,2); // initialize the lcd for 16 chars 2 lines
lcd.setCursor(0,0); // Start at character 0 on line 0
lcd.print("PINGER");
Serial.begin(9600);
}
void loop() {
delay(100); // Wait - 29ms should be the shortest delay between pings
unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS)
dist = uS/US_ROUNDTRIP_CM;
lcd.setCursor(8,0);
lcd.print(dist);
lcd.print("cm ");
Serial.print('H'); // send a header character
Serial.write(dist);
}