Librería HCSR04 con algunas modificaciones
Diff: HCSR042.h
- Revision:
- 0:70e05cce830a
diff -r 000000000000 -r 70e05cce830a HCSR042.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HCSR042.h Thu Dec 04 06:27:21 2014 +0000 @@ -0,0 +1,39 @@ +//Library for controlling ultrasonic module HCSR04 +//Ported by hiawoood from arduino library orgininally created by ITead studio. +//Instantiate object by supplying the proper pin numbers of "trigger" and "echo" +//e.g. +/* + int main() { + Ultrasonic sensor(p5, p6); + while(1){ + long distance = sensor.distance(CM); + printf("Distance:%d\n"); + wait(0.1); + } + } +*/ + + + +#ifndef HCSR042_H +#define HCSR042_H + +#include "mbed.h" + +#define CM 1 +#define INC 0 + +class HCSR042 { + public: + HCSR042(PinName t, PinName e); + long echo_duration(); + long distance(int sys); + + private: + DigitalOut trig; + DigitalIn echo; + Timer timer; + long duration,distacne_cm,distance_inc; +}; + +#endif \ No newline at end of file