Librería HCSR04 con algunas modificaciones

Dependents:   ZMOTO42

Committer:
jaruiz
Date:
Thu Dec 04 06:27:21 2014 +0000
Revision:
0:70e05cce830a
Libreria HCSR04 con algunas modificaciones

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jaruiz 0:70e05cce830a 1 //Library for controlling ultrasonic module HCSR04
jaruiz 0:70e05cce830a 2 //Ported by hiawoood from arduino library orgininally created by ITead studio.
jaruiz 0:70e05cce830a 3 //Instantiate object by supplying the proper pin numbers of "trigger" and "echo"
jaruiz 0:70e05cce830a 4 //e.g.
jaruiz 0:70e05cce830a 5 /*
jaruiz 0:70e05cce830a 6 int main() {
jaruiz 0:70e05cce830a 7 Ultrasonic sensor(p5, p6);
jaruiz 0:70e05cce830a 8 while(1){
jaruiz 0:70e05cce830a 9 long distance = sensor.distance(CM);
jaruiz 0:70e05cce830a 10 printf("Distance:%d\n");
jaruiz 0:70e05cce830a 11 wait(0.1);
jaruiz 0:70e05cce830a 12 }
jaruiz 0:70e05cce830a 13 }
jaruiz 0:70e05cce830a 14 */
jaruiz 0:70e05cce830a 15
jaruiz 0:70e05cce830a 16
jaruiz 0:70e05cce830a 17
jaruiz 0:70e05cce830a 18 #ifndef HCSR042_H
jaruiz 0:70e05cce830a 19 #define HCSR042_H
jaruiz 0:70e05cce830a 20
jaruiz 0:70e05cce830a 21 #include "mbed.h"
jaruiz 0:70e05cce830a 22
jaruiz 0:70e05cce830a 23 #define CM 1
jaruiz 0:70e05cce830a 24 #define INC 0
jaruiz 0:70e05cce830a 25
jaruiz 0:70e05cce830a 26 class HCSR042 {
jaruiz 0:70e05cce830a 27 public:
jaruiz 0:70e05cce830a 28 HCSR042(PinName t, PinName e);
jaruiz 0:70e05cce830a 29 long echo_duration();
jaruiz 0:70e05cce830a 30 long distance(int sys);
jaruiz 0:70e05cce830a 31
jaruiz 0:70e05cce830a 32 private:
jaruiz 0:70e05cce830a 33 DigitalOut trig;
jaruiz 0:70e05cce830a 34 DigitalIn echo;
jaruiz 0:70e05cce830a 35 Timer timer;
jaruiz 0:70e05cce830a 36 long duration,distacne_cm,distance_inc;
jaruiz 0:70e05cce830a 37 };
jaruiz 0:70e05cce830a 38
jaruiz 0:70e05cce830a 39 #endif