Biblioteca para uso do ultrassom HC-SR04

Dependents:   Sonar-HC-SR04 CarrinhoLabirinto Nucleo_Us_ticker_20160803 ProjetoSO ... more

Embed: (wiki syntax)

« Back to documentation index

HCSR04 Class Reference

HCSR04 Class Reference

Sonar HC-SR04 example. More...

#include <HCSR04.h>

Public Member Functions

 HCSR04 (PinName trigger, PinName echo)
 Constructor, create HCSR04 instance.
float readEcho (void)
 It make a reading of the sonar Faz uma leitura do sonar.
float getCm (void)
 It messures the distance in centimeter "cm".
float getIn (void)
 Mede a distência em polegadas "in".

Detailed Description

Sonar HC-SR04 example.

 #include "mbed.h"
 #include "HCSR04.h"

 DigitalOut myled(LED1);
 Serial pc(USBTX,USBRX);     

 HCSR04 sonar(PTD5, PTA13);

 int main() {
     while(1) {
         printf("Distancia detectada pelo sensor Frente %.2f cm \n", sonar.getCm()); 
         wait_ms(1000);
     }
 }

Definition at line 63 of file HCSR04.h.


Constructor & Destructor Documentation

HCSR04 ( PinName  trigger,
PinName  echo 
)

Constructor, create HCSR04 instance.

Parameters:
triggerTRIG pin
echoECHO pin
Author:
Nestor Pereira-Neto Team: SalvadorEngenharia

LICENSE

Copyright (c) 2010 ARM Limited

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

DESCRIPTION

Biblioteca para uso do sonar HC-SR04, possui rotinas para permitir medições de distências retornado valores em centímetros, polegadas ou o tempo percorrido pelo som (em microsegundos). Esta biblioteca pode ser usada com qualquer pino do microcontrolador.

Definition at line 39 of file HCSR04.cpp.


Member Function Documentation

float getCm ( void   )

It messures the distance in centimeter "cm".

Returns:
Distance in centimeter

Definition at line 43 of file HCSR04.cpp.

float getIn ( void   )

Mede a distência em polegadas "in".

Returns:
Distência em in

Definition at line 48 of file HCSR04.cpp.

float readEcho ( void   )

It make a reading of the sonar Faz uma leitura do sonar.

Returns:
Tempo do pulso echo em microsegundos

Definition at line 53 of file HCSR04.cpp.