Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: hcsr04.h
- Revision:
- 0:86b2086be101
- Child:
- 1:067e3b441952
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hcsr04.h Mon Apr 14 08:23:09 2014 +0000
@@ -0,0 +1,50 @@
+/* File: HCSR04.h
+ * Author: Antonio Buonanno
+ *Board: STM NUCLEO F401RE,
+ *Hardware: Ultrasonic Range HC-SR04,
+ *
+ *This work derived from Arduino library,
+ *
+ * Desc: driver for HCSR04 Ultrasonic Range Finder. The returned range
+ * is in units of meters.
+ *
+ *
+ *
+*/
+
+/* EXAMPLE
+#include "mbed.h"
+#include "hcsr04.h"
+
+//D12 TRIGGER D11 ECHO
+ HCSR04 sensor(D12, D11);
+int main() {
+ while(1) {
+
+ long distance = sensor.distance();
+ printf("distanza %d \n",distance);
+ wait(1.0); // 1 sec
+
+ }
+}
+*/
+#ifndef hcsr04_H
+#define hcsr04_H
+#include "mbed.h"
+
+
+
+class HCSR04 {
+ public:
+ HCSR04(PinName t, PinName e);
+ long echo_duration();
+ long distance();
+
+ private:
+ DigitalOut trig;
+ DigitalIn echo;
+ Timer timer;
+ long duration,distance_cm;
+};
+
+#endif
\ No newline at end of file