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.
Dependents: Deber1_Rafael_Franco
Diff: HCSR04.h
- Revision:
- 0:0bda99bb39a4
- Child:
- 2:b9daddc55d12
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/HCSR04.h Tue Oct 18 14:32:12 2011 +0000
@@ -0,0 +1,39 @@
+//Library for controlling ultrasonic module HCSR04
+//Ported by hiawoood from arduino library orgininally created by ITead studio.
+//Instantiate object by supplying the proper pin numbers of "trigger" and "echo"
+//e.g.
+/*
+ int main() {
+ Ultrasonic sensor(p5, p6);
+ while(1){
+ long distance = sensor.distance(CM);
+ printf("Distance:%d\n");
+ wait(0.1);
+ }
+ }
+*/
+
+
+
+#ifndef HCSR04_H
+#define HCSR04_H
+
+#include "mbed.h"
+
+#define CM 1
+#define INC 0
+
+class HCSR04 {
+ public:
+ HCSR04(PinName t, PinName e);
+ long echo_duration();
+ long distance(int sys);
+
+ private:
+ DigitalOut trig;
+ DigitalIn echo;
+ Timer timer;
+ long duration,distacne_cm,distance_inc;
+};
+
+#endif
\ No newline at end of file