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.
Dependents: inverted_pendulum_system
Fork of HCSR04 by
hcsr04.h
00001 ////////////////////////////////////////////////////////////////////////////////// 00002 // Company: edinburgh of university 00003 // Engineer: ZEjun DU 00004 // 00005 // Create Date: 2017/08/20 13:06:52 00006 // Design Name: Inverted Pendulum Balancer 00007 // Module Name: distance sensor 00008 // Tool Versions: “Keil 5” or “Mbed Complie Online” 00009 // Description: this part is basic function of position to get distance from distance sensor hcsr04.cpp 00010 // 00011 // 00012 ////////////////////////////////////////////////////////////////////////////////// 00013 00014 #ifndef MBED_HCSR04_H 00015 #define MBED_HCSR04_H 00016 00017 #include "mbed.h" 00018 00019 /** HCSR04 Class(es) 00020 */ 00021 00022 class HCSR04 00023 { 00024 public: 00025 /** Create a HCSR04 object connected to the specified pin 00026 * @param pin i/o pin to connect to 00027 */ 00028 HCSR04(PinName TrigPin,PinName EchoPin); 00029 ~HCSR04(); 00030 00031 /** Return the distance from obstacle in cm 00032 * @param distance in cms and returns -1, in case of failure 00033 */ 00034 unsigned int get_dist_cm(void); 00035 /** Return the pulse duration equal to sonic waves travelling to obstacle and back to receiver. 00036 * @param pulse duration in microseconds. 00037 */ 00038 unsigned int get_pulse_us(void); 00039 /** Generates the trigger pulse of 10us on the trigger PIN. 00040 */ 00041 void start(void ); 00042 void isr_rise(void); 00043 void isr_fall(void); 00044 void fall (void (*fptr)(void)); 00045 void rise (void (*fptr)(void)); 00046 00047 00048 00049 private: 00050 00051 Timer pulsetime; 00052 DigitalOut trigger; 00053 InterruptIn echo; 00054 unsigned int pulsedur; 00055 unsigned int distance; 00056 // float pulsedur; 00057 // float distance; 00058 00059 00060 }; 00061 00062 #endif
Generated on Mon Aug 1 2022 20:00:26 by
1.7.2
