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

Devantech SRF04 sonar

Devantech SRF04 sonar.
srf04.jpg
The sonar can be connected to any two I/O pins but requires a +5v regulated supply. The sonar can measure distances up to about 300 cm. It may be defined using:
According to the datasheet you should not read the sensor within 50mS 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. But if you are using more than one sonar then you will need to manually add a suitable delay to stop this sensor receiving ghost echoes from other sonars.
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;
Function Summary

Valid XHTML 1.0 Transitional