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.cpp
- Revision:
- 0:2d8f1aed9d70
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hcsr04.cpp Mon Jul 06 13:59:08 2020 +0000
@@ -0,0 +1,27 @@
+/*#include "hcsr04.h"
+#include "mbed.h"
+
+HCSR04::HCSR04(PinName t, PinName e) : trig(t), echo(e) {}
+ long HCSR04::echo_duration() {
+
+ timer.reset(); //reset timer
+ trig=0; // trigger low
+ wait_us(2); // wait
+ trig=1; // trigger high
+ wait_us(10);
+ trig=0; // trigger low
+ while(!echo); // start pulseIN
+ timer.start();
+ while(echo);
+ timer.stop();
+ return timer.read_us();
+
+}
+
+//return distance in cm
+long HCSR04::distance(){
+ duration = echo_duration();
+ distance_cm = (duration/2)/29.1 ;
+ return distance_cm;
+
+}*/
\ No newline at end of file