Librería HCSR04 con algunas modificaciones
HCSR044.h@0:d4d01f7a6c68, 2014-12-04 (annotated)
- Committer:
- jaruiz
- Date:
- Thu Dec 04 06:28:23 2014 +0000
- Revision:
- 0:d4d01f7a6c68
Librer?a HCSR04 con algunas modificaciones
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jaruiz | 0:d4d01f7a6c68 | 1 | //Library for controlling ultrasonic module HCSR04 |
jaruiz | 0:d4d01f7a6c68 | 2 | //Ported by hiawoood from arduino library orgininally created by ITead studio. |
jaruiz | 0:d4d01f7a6c68 | 3 | //Instantiate object by supplying the proper pin numbers of "trigger" and "echo" |
jaruiz | 0:d4d01f7a6c68 | 4 | //e.g. |
jaruiz | 0:d4d01f7a6c68 | 5 | /* |
jaruiz | 0:d4d01f7a6c68 | 6 | int main() { |
jaruiz | 0:d4d01f7a6c68 | 7 | Ultrasonic sensor(p5, p6); |
jaruiz | 0:d4d01f7a6c68 | 8 | while(1){ |
jaruiz | 0:d4d01f7a6c68 | 9 | long distance = sensor.distance(CM); |
jaruiz | 0:d4d01f7a6c68 | 10 | printf("Distance:%d\n"); |
jaruiz | 0:d4d01f7a6c68 | 11 | wait(0.1); |
jaruiz | 0:d4d01f7a6c68 | 12 | } |
jaruiz | 0:d4d01f7a6c68 | 13 | } |
jaruiz | 0:d4d01f7a6c68 | 14 | */ |
jaruiz | 0:d4d01f7a6c68 | 15 | |
jaruiz | 0:d4d01f7a6c68 | 16 | |
jaruiz | 0:d4d01f7a6c68 | 17 | |
jaruiz | 0:d4d01f7a6c68 | 18 | #ifndef HCSR044_H |
jaruiz | 0:d4d01f7a6c68 | 19 | #define HCSR044_H |
jaruiz | 0:d4d01f7a6c68 | 20 | |
jaruiz | 0:d4d01f7a6c68 | 21 | #include "mbed.h" |
jaruiz | 0:d4d01f7a6c68 | 22 | |
jaruiz | 0:d4d01f7a6c68 | 23 | #define CM 1 |
jaruiz | 0:d4d01f7a6c68 | 24 | #define INC 0 |
jaruiz | 0:d4d01f7a6c68 | 25 | |
jaruiz | 0:d4d01f7a6c68 | 26 | class HCSR044 { |
jaruiz | 0:d4d01f7a6c68 | 27 | public: |
jaruiz | 0:d4d01f7a6c68 | 28 | HCSR044(PinName t, PinName e); |
jaruiz | 0:d4d01f7a6c68 | 29 | long echo_duration(); |
jaruiz | 0:d4d01f7a6c68 | 30 | long distance(int sys); |
jaruiz | 0:d4d01f7a6c68 | 31 | |
jaruiz | 0:d4d01f7a6c68 | 32 | private: |
jaruiz | 0:d4d01f7a6c68 | 33 | DigitalOut trig; |
jaruiz | 0:d4d01f7a6c68 | 34 | DigitalIn echo; |
jaruiz | 0:d4d01f7a6c68 | 35 | Timer timer; |
jaruiz | 0:d4d01f7a6c68 | 36 | long duration,distacne_cm,distance_inc; |
jaruiz | 0:d4d01f7a6c68 | 37 | }; |
jaruiz | 0:d4d01f7a6c68 | 38 | |
jaruiz | 0:d4d01f7a6c68 | 39 | #endif |