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 00002 00003 #ifndef MBED_HCSR04_H 00004 #define MBED_HCSR04_H 00005 00006 #include "mbed.h" 00007 00008 /** HCSR04 Class(es) 00009 */ 00010 00011 class HCSR04 00012 { 00013 public: 00014 /** Create a HCSR04 object connected to the specified pin 00015 * @param pin i/o pin to connect to 00016 */ 00017 HCSR04(PinName TrigPin,PinName EchoPin); 00018 ~HCSR04(); 00019 00020 /** Return the distance from obstacle in cm 00021 * @param distance in cms and returns -1, in case of failure 00022 */ 00023 unsigned int get_dist_cm(void); 00024 /** Return the pulse duration equal to sonic waves travelling to obstacle and back to receiver. 00025 * @param pulse duration in microseconds. 00026 */ 00027 unsigned int get_pulse_us(void); 00028 /** Generates the trigger pulse of 10us on the trigger PIN. 00029 */ 00030 void start(void ); 00031 void isr_rise(void); 00032 void isr_fall(void); 00033 void fall (void (*fptr)(void)); 00034 void rise (void (*fptr)(void)); 00035 00036 00037 00038 private: 00039 00040 Timer pulsetime; 00041 DigitalOut trigger; 00042 InterruptIn echo; 00043 unsigned int pulsedur; 00044 unsigned int distance; 00045 }; 00046 00047 #endif
Generated on Wed Aug 3 2022 04:40:49 by
