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