A distance measurement class using ultrasonic sensor HC-SR04.

Dependents:   Esercitazione4_4 HC-SR04 Group10_slave Oled_Gus ... more

The purpose of this library is to encourage students to develope their own classes. Instructions how to follow the development of this library for ultrasonic distance measurement are given here.

Revision:
5:a667b621f625
Parent:
4:aae70f15357f
Child:
6:cf3e4e307d15
--- a/HCSR04.h	Mon Dec 07 09:37:21 2015 +0000
+++ b/HCSR04.h	Mon Dec 07 09:57:48 2015 +0000
@@ -8,13 +8,16 @@
  * #include "mbed.h"
  * #include "HCSR04.h"
  *
- * Serial pc(USBTX, USBRX);    // communication with terminal
- * 
+ * Serial pc(USBTX, USBRX);
+ *
  * int main() {
- *     HCSR04 sensor(p5, p7);     // instantiate the sensor object
+ *     HCSR04 sensor(p5, p7);
+ *     sensor.setRanges(10, 110);
+ *     pc.printf("Min. range = %g cm\n\rMax. range = %g cm\n\r",
+ *       sensor.getMinRange(), sensor.getMaxRange());
  *     while(1) {
- *         pc.printf("Distance: %5.1f cm\r", sensor.getDistance_cm());
- *         wait_ms(975); // print the result every 1 second
+ *         pc.printf("Distance: %5.1f mm\r", sensor.getDistance_mm());
+ *         wait_ms(500);
  *     }
  * }
  * @endcode