a

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 29 of file HCSR04.h.


Constructor & Destructor Documentation

HCSR04 ( PinName  trigger,
PinName  echo 
)

Constructor, create HCSR04 instance.

Parameters:
triggerTRIG pin
echoECHO pin

Definition at line 5 of file HCSR04.cpp.


Member Function Documentation

float getCm ( void   )

It messures the distance in centimeter "cm".

Returns:
Distance in centimeter

Definition at line 9 of file HCSR04.cpp.

float getIn ( void   )

Mede a distência em polegadas "in".

Returns:
Distência em in

Definition at line 14 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 19 of file HCSR04.cpp.