WebbotLib AVR library
WebbotLib It just does it
ááC++ádocumentationááCádocumentation

PING Sonar

Parallax PING sonar.
sonar parallax ping.jpg
The sonar can be connected to any I/O pin but requires a +5v regulated supply. The sonar can measure distances in the range 2 to 300 cm.
Example
Assuming you have called your sensor 'myDistance' in Project Designer then it can be accessed as follows:-
myDistance.read();
DISTANCE_TYPE cm = myDistance.getDistance();
cout << "Distance=" << cm;
Or dumped to the standard out destination using:-
cout << myDistance;
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. If you are using multiple sonars then you will need to manually add delays between reading different sonars to avoid one receiving a ghost echo from another sonar.
Function Summary

Valid XHTML 1.0 Transitional