PING))) documentation v1.5
Copyright © Parallax Inc. PING))) Ultrasonic Distance Sensor (#28015) v1.5 2/15/2008 Page 11 of 12
* Values to derive conversion factors are selected to prevent roll-over
* past the 15-bit positive values of Javelin Stamp integers.
*/
/**
* @return PING))) distance value in inches
*/
public int getIn() {
return (getRaw() * 3 / 51); // raw * 0.058824
}
/**
* @return PING))) distance value in tenths of inches
*/
public int getIn10() {
return (getRaw() * 3 / 5); // raw / 1.6667
}
/*
* The PING))) returns a pulse width of 29.033 uS per centimeter. As the
* Javelin pulseIn() round-trip echo time is in 8.68 uS units, this is the
* same as a one-way trip in 4.34 uS units. Dividing 29.033 by 4.34 we
* get a time-per-centimeter conversion factor of 6.6896.
*
* Values to derive conversion factors are selected to prevent roll-over
* past the 15-bit positive values of Javelin Stamp integers.
*/
/**
* @return PING))) distance value in centimeters
*/
public int getCm() {
return (getRaw() * 3 / 20); // raw / 6.6667
}
/**
* @return PING))) distance value in millimeters
*/
public int getMm() {
return (getRaw() * 3 / 2); // raw / 0.6667
}
}
This simple demo illustrates the use of the PING))) ultrasonic range finder class with
the Javelin Stamp:
import stamp.core.*;
import stamp.peripheral.sensor.Ping;
public class testPing {
public static final char HOME = 0x01;
public static void main() {
Ping range = new Ping(CPU.pin0);
StringBuffer msg = new StringBuffer();
int distance;