dillerdasker

Dependents:   RoboticHackathon RoboticHackathon2 RoboticHackathonFINAL

Revision:
0:506625fdcd0e
Child:
1:d9083ad270f5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HCSR04.h	Sat Apr 05 07:55:59 2014 +0000
@@ -0,0 +1,50 @@
+//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. 
+/*
+#include "mbed.h"
+#include "HCSR04.h"
+Serial pc(USBTX, USBRX);
+
+int main() {
+    
+    HCSR04 sensor(PTE1, PTB3);
+    while(1){
+       
+        long distance = sensor.distance(CM);
+            
+        pc.printf("Distance: %ld \r\n", distance);
+        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);
+    
+    HCSR05();
+    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