Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
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:
-
trigger TRIG pin echo ECHO 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.
Generated on Sun Aug 7 2022 14:02:38 by
1.7.2