Sonar Simples
Dependencies: HCSR04
Revision 0:e2112f4ac360, committed 2016-09-29
- Comitter:
- Edgar2016
- Date:
- Thu Sep 29 16:49:08 2016 +0000
- Commit message:
- Sonar Simples
Changed in this revision
--- /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
--- /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 + } +} +*/
--- /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
--- /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