Sonar Simples

Dependencies:   HCSR04

Files at this revision

API Documentation at this revision

Comitter:
Edgar2016
Date:
Thu Sep 29 16:49:08 2016 +0000
Commit message:
Sonar Simples

Changed in this revision

HCSR04.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
sonar.cpp Show annotated file Show diff for this revision Revisions of this file
sonar.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r e2112f4ac360 HCSR04.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HCSR04.lib	Thu Sep 29 16:49:08 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/antoniolinux/code/HCSR04/#86b2086be101
diff -r 000000000000 -r e2112f4ac360 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Sep 29 16:49:08 2016 +0000
@@ -0,0 +1,13 @@
+/**main.cpp
+#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  
+        }
+}
+*/
diff -r 000000000000 -r e2112f4ac360 sonar.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sonar.cpp	Thu Sep 29 16:49:08 2016 +0000
@@ -0,0 +1,13 @@
+#include "sonar.h"
+#include "mbed.h"
+#include "hcsr04.h"
+
+Sonar::Sonar():
+_ultrasonic(Sonar::trigger, Sonar::echo){   
+}
+
+float Sonar::lerDistancia(HCSR04 _HCSR04){
+    _HCSR04.distance();
+    float distance = _HCSR04;
+    return distance;
+}
\ No newline at end of file
diff -r 000000000000 -r e2112f4ac360 sonar.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sonar.h	Thu Sep 29 16:49:08 2016 +0000
@@ -0,0 +1,23 @@
+#ifndef Sonar_H
+#define Sonar_H
+ 
+#include "mbed.h"
+#include "hcsr04.h"
+ 
+class Sonar
+{
+    static const PinName trigger = D1; //Define o pino para o trigger 
+    static const PinName echo = D0; //Define o pino para o echo
+   
+    //Inicializa o sensor nos pinos definidos acima
+    HCSR04 _HCSR04;
+    
+public:
+    Sonar();
+    ~Sonar();
+    float lerDistancia(HCSR04 _HCSR04);
+    
+        
+};
+ 
+#endif
\ No newline at end of file