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/hcsr04.h@0:0f497d629677, 2020-11-19 (annotated)
- Committer:
- grupo_17_2020
- Date:
- Thu Nov 19 12:07:27 2020 +0000
- Revision:
- 0:0f497d629677
el codigo completo del Asistente de Servicio Personal Interaccional - 01
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
grupo_17_2020 | 0:0f497d629677 | 1 | /* File: HCSR04.h |
grupo_17_2020 | 0:0f497d629677 | 2 | * Author: Antonio Buonanno |
grupo_17_2020 | 0:0f497d629677 | 3 | *Board: STM NUCLEO F401RE, |
grupo_17_2020 | 0:0f497d629677 | 4 | *Hardware: Ultrasonic Range HC-SR04, |
grupo_17_2020 | 0:0f497d629677 | 5 | * |
grupo_17_2020 | 0:0f497d629677 | 6 | *This work derived from Arduino library, |
grupo_17_2020 | 0:0f497d629677 | 7 | * |
grupo_17_2020 | 0:0f497d629677 | 8 | * Desc: driver for HCSR04 Ultrasonic Range Finder. The returned range |
grupo_17_2020 | 0:0f497d629677 | 9 | * is in units of meters. |
grupo_17_2020 | 0:0f497d629677 | 10 | * |
grupo_17_2020 | 0:0f497d629677 | 11 | * |
grupo_17_2020 | 0:0f497d629677 | 12 | * |
grupo_17_2020 | 0:0f497d629677 | 13 | */ |
grupo_17_2020 | 0:0f497d629677 | 14 | |
grupo_17_2020 | 0:0f497d629677 | 15 | /* EXAMPLE |
grupo_17_2020 | 0:0f497d629677 | 16 | #include "mbed.h" |
grupo_17_2020 | 0:0f497d629677 | 17 | #include "hcsr04.h" |
grupo_17_2020 | 0:0f497d629677 | 18 | |
grupo_17_2020 | 0:0f497d629677 | 19 | //D12 TRIGGER D11 ECHO |
grupo_17_2020 | 0:0f497d629677 | 20 | HCSR04 sensor(D12, D11); |
grupo_17_2020 | 0:0f497d629677 | 21 | int main() { |
grupo_17_2020 | 0:0f497d629677 | 22 | while(1) { |
grupo_17_2020 | 0:0f497d629677 | 23 | |
grupo_17_2020 | 0:0f497d629677 | 24 | long distance = sensor.distance(); |
grupo_17_2020 | 0:0f497d629677 | 25 | printf("distanza %d \n",distance); |
grupo_17_2020 | 0:0f497d629677 | 26 | wait(1.0); // 1 sec |
grupo_17_2020 | 0:0f497d629677 | 27 | |
grupo_17_2020 | 0:0f497d629677 | 28 | } |
grupo_17_2020 | 0:0f497d629677 | 29 | } |
grupo_17_2020 | 0:0f497d629677 | 30 | */ |
grupo_17_2020 | 0:0f497d629677 | 31 | #ifndef hcsr04_H |
grupo_17_2020 | 0:0f497d629677 | 32 | #define hcsr04_H |
grupo_17_2020 | 0:0f497d629677 | 33 | #include "mbed.h" |
grupo_17_2020 | 0:0f497d629677 | 34 | |
grupo_17_2020 | 0:0f497d629677 | 35 | |
grupo_17_2020 | 0:0f497d629677 | 36 | |
grupo_17_2020 | 0:0f497d629677 | 37 | class HCSR04 { |
grupo_17_2020 | 0:0f497d629677 | 38 | public: |
grupo_17_2020 | 0:0f497d629677 | 39 | HCSR04(PinName t, PinName e); |
grupo_17_2020 | 0:0f497d629677 | 40 | long echo_duration(); |
grupo_17_2020 | 0:0f497d629677 | 41 | long distance(); |
grupo_17_2020 | 0:0f497d629677 | 42 | |
grupo_17_2020 | 0:0f497d629677 | 43 | private: |
grupo_17_2020 | 0:0f497d629677 | 44 | DigitalOut trig; |
grupo_17_2020 | 0:0f497d629677 | 45 | DigitalIn echo; |
grupo_17_2020 | 0:0f497d629677 | 46 | Timer timer; |
grupo_17_2020 | 0:0f497d629677 | 47 | long duration,distance_cm; |
grupo_17_2020 | 0:0f497d629677 | 48 | }; |
grupo_17_2020 | 0:0f497d629677 | 49 | |
grupo_17_2020 | 0:0f497d629677 | 50 | #endif |