Devantech/SRF04_Sonar.h

Devantech SRF04 sonar.

The sonar can be connected to any two I/O pins but requires a +5v regulated supply. On the Axon this means using an ADC pin. The sonar can measure distances up to about 300 cm. It may be defined using:

Devantech_SRF04 sensor = MAKE_Devantech_SRF04(F0,F1);

Where F0 is the microcontroller pin connected to the 'Trigger Pulse Input' of the device; and F1 is the microcontroller pin connected to the 'Echo Pulse Output' of the device.

The sensor should be initialised in appInitHardware using:-

distanceInit(sensor);

The sensor can then be read using:-

distanceRead(sensor);

and then the distance in cm will be in sensor.distance.cm

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.