done

Dependents:   AwesomeAlarm_BLE

Revision:
0:d1d7bb1c1f6c
Child:
2:9daf23ed9d84
Child:
3:12d6d751f4fc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HCSR04.cpp	Thu Feb 05 19:00:51 2015 +0000
@@ -0,0 +1,30 @@
+#include "HCSR04.h"
+#include "mbed.h"
+
+
+HCSR04::HCSR04(PinName trigger, PinName echo) : _t(trigger), _e(echo) {
+    wait(0.1);
+    }
+
+float HCSR04::getCm(void){
+    distcm = readEcho()/58;
+    return distcm;
+    }
+
+float HCSR04::getIn(void){
+    distin = readEcho()/148;
+    return distin;
+    }
+
+float HCSR04::readEcho(void){     
+    _t=1;                       //Inicio do trigger
+    wait_us(10);                //10us de pulso
+    _t=0;                       //Fim do trigger
+    while(!_e);
+    _tempo.start();
+    while(_e);
+    tdist = _tempo.read_us();   //Leitura do tempo transcorrido 
+    _tempo.stop();              //Paro o temporizador
+    _tempo.reset();             //Reset para o próximo ciclo
+    return tdist;
+}
\ No newline at end of file