Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of HCSR04 by
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 float echo_duration(); 00030 float distance(int sys); 00031 00032 private: 00033 DigitalOut trig; 00034 DigitalIn echo; 00035 Timer timer; 00036 float duration,distacne_cm,distance_inc; 00037 }; 00038 00039 #endif
Generated on Sat Jul 16 2022 21:02:39 by
1.7.2
