Parallax PING sonar.
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.
Assuming you have called your sensor 'myDistance' in Project Designer then it can be accessed as follows:-
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.
- dump - Dump the last read sensor values to the standard output device.
- dumpTo - Dump the contents of the sensor to the specified output stream.
- getDistance - Returns the distance in whole cm detected by the sensor during the last read().
- getTimeLastRead - Returns the value of the clock at the time when the sensor was last read.
- read - Read the sensor and store its current values. Returns TRUE if the sensor has been read successfully, or FALSE if the sensor is busy in which case the read values are unchanged.