Library for controlling ultrasonic ranging module HCSR04 Ported by hiawoood from arduino library orgininally created by ITead studio.
Dependents: JakKrisowy JakKrisowy_ golonkaczosniur
Fork of HCSR04 by
HCSR04.h@1:01ecd819e4ee, 2016-07-07 (annotated)
- Committer:
- yruiewyrui3
- Date:
- Thu Jul 07 12:54:59 2016 +0000
- Revision:
- 1:01ecd819e4ee
- Parent:
- 0:0bda99bb39a4
.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yruiewyrui3 | 1:01ecd819e4ee | 1 | /* File: HCSR04.h |
yruiewyrui3 | 1:01ecd819e4ee | 2 | * Author: Antonio Buonanno |
yruiewyrui3 | 1:01ecd819e4ee | 3 | *Board: STM NUCLEO F401RE, |
yruiewyrui3 | 1:01ecd819e4ee | 4 | *Hardware: Ultrasonic Range HC-SR04, |
yruiewyrui3 | 1:01ecd819e4ee | 5 | * |
yruiewyrui3 | 1:01ecd819e4ee | 6 | *This work derived from Arduino library, |
yruiewyrui3 | 1:01ecd819e4ee | 7 | * |
yruiewyrui3 | 1:01ecd819e4ee | 8 | * Desc: driver for HCSR04 Ultrasonic Range Finder. The returned range |
yruiewyrui3 | 1:01ecd819e4ee | 9 | * is in units of meters. |
yruiewyrui3 | 1:01ecd819e4ee | 10 | * |
yruiewyrui3 | 1:01ecd819e4ee | 11 | * |
yruiewyrui3 | 1:01ecd819e4ee | 12 | * |
aralshukaili | 0:0bda99bb39a4 | 13 | */ |
aralshukaili | 0:0bda99bb39a4 | 14 | |
yruiewyrui3 | 1:01ecd819e4ee | 15 | /* EXAMPLE |
yruiewyrui3 | 1:01ecd819e4ee | 16 | #include "mbed.h" |
yruiewyrui3 | 1:01ecd819e4ee | 17 | #include "hcsr04.h" |
aralshukaili | 0:0bda99bb39a4 | 18 | |
yruiewyrui3 | 1:01ecd819e4ee | 19 | //D12 TRIGGER D11 ECHO |
yruiewyrui3 | 1:01ecd819e4ee | 20 | HCSR04 sensor(D12, D11); |
yruiewyrui3 | 1:01ecd819e4ee | 21 | int main() { |
yruiewyrui3 | 1:01ecd819e4ee | 22 | while(1) { |
yruiewyrui3 | 1:01ecd819e4ee | 23 | |
yruiewyrui3 | 1:01ecd819e4ee | 24 | long distance = sensor.distance(); |
yruiewyrui3 | 1:01ecd819e4ee | 25 | printf("distanza %d \n",distance); |
yruiewyrui3 | 1:01ecd819e4ee | 26 | wait(1.0); // 1 sec |
yruiewyrui3 | 1:01ecd819e4ee | 27 | |
yruiewyrui3 | 1:01ecd819e4ee | 28 | } |
yruiewyrui3 | 1:01ecd819e4ee | 29 | } |
yruiewyrui3 | 1:01ecd819e4ee | 30 | */ |
yruiewyrui3 | 1:01ecd819e4ee | 31 | #ifndef hcsr04_H |
yruiewyrui3 | 1:01ecd819e4ee | 32 | #define hcsr04_H |
aralshukaili | 0:0bda99bb39a4 | 33 | #include "mbed.h" |
aralshukaili | 0:0bda99bb39a4 | 34 | |
aralshukaili | 0:0bda99bb39a4 | 35 | |
aralshukaili | 0:0bda99bb39a4 | 36 | class HCSR04 { |
aralshukaili | 0:0bda99bb39a4 | 37 | public: |
yruiewyrui3 | 1:01ecd819e4ee | 38 | HCSR04(PinName t, PinName e, long to); |
aralshukaili | 0:0bda99bb39a4 | 39 | long echo_duration(); |
yruiewyrui3 | 1:01ecd819e4ee | 40 | long distance(); |
yruiewyrui3 | 1:01ecd819e4ee | 41 | |
aralshukaili | 0:0bda99bb39a4 | 42 | private: |
aralshukaili | 0:0bda99bb39a4 | 43 | DigitalOut trig; |
aralshukaili | 0:0bda99bb39a4 | 44 | DigitalIn echo; |
aralshukaili | 0:0bda99bb39a4 | 45 | Timer timer; |
yruiewyrui3 | 1:01ecd819e4ee | 46 | long duration,distance_cm,time_out; |
aralshukaili | 0:0bda99bb39a4 | 47 | }; |
yruiewyrui3 | 1:01ecd819e4ee | 48 | |
aralshukaili | 0:0bda99bb39a4 | 49 | #endif |