Hi guys. I have since got something to run in Processing, with the film split into stills at 25fps. Both Processing and Arduino sketches run fine with a push button, but I'm having trouble adapting the code to get Processing to read the PING as a switch. I want arduino to trigger processing when the distance is less than 33 inches. Have been on this for days. Any ideas where I'm going wrong? I know it's quite an old post, so will repost if I don't hear back.
Thanks for your help,
Ben.
Code adapted from:
http://www.arduino.cc/en/Tutorial/Ping// this constant won't change. It's the pin number
// of the sensor's output:
const int pingPin = 4;
void setup() {
Serial.begin(9600);
pinMode(pingPin, INPUT);
}
void loop()
{
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, inches;
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
// Serial.println(duration); // Print value to serial monitor
// If there is a an object less than 33 inches from the sensor send 1 to
// processing, otherwise send 0. (Number of microseconds divided by 74
// gives ms per inch. Half this value gives the distance of the object)
if (duration / 74 / 2 < 32)
{
Serial.print(1, BYTE);
} else {
Serial.print(0, BYTE);
}
delay(100);
}