Library for controlling ultrasonic ranging module HCSR04 Ported by hiawoood from arduino library orgininally created by ITead studio.
Diff: HCSR04.h
- Revision:
- 1:b3401c36a10b
- Parent:
- 0:0bda99bb39a4
diff -r 0bda99bb39a4 -r b3401c36a10b HCSR04.h --- a/HCSR04.h Tue Oct 18 14:32:12 2011 +0000 +++ b/HCSR04.h Sun Jun 16 04:37:08 2019 +0000 @@ -1,39 +1,20 @@ -//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 HCSR04_H -#define HCSR04_H +#ifndef Ultrasonic_H +#define Ultrasonic_H #include "mbed.h" -#define CM 1 -#define INC 0 - -class HCSR04 { +class Ultrasonic { public: - HCSR04(PinName t, PinName e); - long echo_duration(); - long distance(int sys); + Ultrasonic(PinName t, PinName e); + int echo_duration(); + int distance(); + int interval; private: DigitalOut trig; DigitalIn echo; Timer timer; - long duration,distacne_cm,distance_inc; + int duration,_distance; }; #endif \ No newline at end of file