WebbotLib AVR library
WebbotLib It just does it


Parallax PING sonar.
sonar parallax ping.jpg
The sonar can be connected to any I/O pin but requires a +5v regulated supply. On the Axon this means using an ADC pin. The sonar can measure distances in the range 2 to 300 cm. It may be defined using:
PingSonar sensor = MAKE_PingSonar(F0);
Where F0 is changed to be the required ADC input pin.
The sensor should be initialised in appInitHardware using:-
The sensor can then be read using:-
and then the distance in cm will be in sensor.distance.cm
According to the datasheet you should not read the sensor within 200ÁS of taking the previous reading. Otherwise you will get ghost echoes from the previous reading. This library will automatically detect if that happens and, in the event, will return the previous reading.

Valid XHTML 1.0 Transitional