Library for controlling ultrasonic ranging module HCSR04 Ported by hiawoood from arduino library orgininally created by ITead studio.
Dependents: Ultrasonic test ZMOTO42 catchCats ... more
HCSR04.h
00001 //Library for controlling ultrasonic module HCSR04 00002 //Ported by hiawoood from arduino library orgininally created by ITead studio. 00003 //Instantiate object by supplying the proper pin numbers of "trigger" and "echo" 00004 //e.g. 00005 /* 00006 int main() { 00007 Ultrasonic sensor(p5, p6); 00008 while(1){ 00009 long distance = sensor.distance(CM); 00010 printf("Distance:%d\n"); 00011 wait(0.1); 00012 } 00013 } 00014 */ 00015 00016 00017 00018 #ifndef HCSR04_H 00019 #define HCSR04_H 00020 00021 #include "mbed.h" 00022 00023 #define CM 1 00024 #define INC 0 00025 00026 class HCSR04 { 00027 public: 00028 HCSR04(PinName t, PinName e); 00029 long echo_duration(); 00030 long distance(int sys); 00031 00032 private: 00033 DigitalOut trig; 00034 DigitalIn echo; 00035 Timer timer; 00036 long duration,distacne_cm,distance_inc; 00037 }; 00038 00039 #endif
Generated on Tue Jul 12 2022 17:05:00 by 1.7.2