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 /* Copyright (c) 2013 Prabhu Desai 00002 * pdtechworld@gmail.com 00003 * 00004 * 00005 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00006 * and associated documentation files (the "Software"), to deal in the Software without restriction, 00007 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 00008 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 00009 * furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included in all copies or 00012 * substantial portions of the Software. 00013 * 00014 * For more details on the sensor : 00015 * http://www.elecfreaks.com/store/hcsr04-ultrasonic-sensor-distance-measuring-module-p-91.html?zenid=pgm8pgnvaodbe36dibq5s1soi3 00016 * 00017 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00018 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00019 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00020 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00021 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00022 */ 00023 00024 #ifndef MBED_HCSR04_H 00025 #define MBED_HCSR04_H 00026 00027 #include "mbed.h" 00028 00029 #define HIGH 1 00030 #define LOW 0 00031 00032 /** HCSR04 Class(es) 00033 */ 00034 00035 class HCSR04 00036 { 00037 public: 00038 /** Create a HCSR04 object connected to the specified pin 00039 * @param pin i/o pin to connect to 00040 */ 00041 HCSR04(PinName TrigPin,PinName EchoPin); 00042 ~HCSR04(); 00043 00044 /** Return the distance from obstacle in cm 00045 * @param distance in cms and returns -1, in case of failure 00046 */ 00047 unsigned int get_dist_cm(void); 00048 /** Return the pulse duration equal to sonic waves travelling to obstacle and back to receiver. 00049 * @param pulse duration in microseconds. 00050 */ 00051 unsigned int get_pulse_us(void); 00052 /** Generates the trigger pulse of 10us on the trigger PIN. 00053 */ 00054 void start(void ); 00055 void isr_rise(void); 00056 void isr_fall(void); 00057 void fall (void (*fptr)(void)); 00058 void rise (void (*fptr)(void)); 00059 00060 00061 00062 private: 00063 00064 Timer pulsetime; 00065 DigitalOut trigger; 00066 InterruptIn echo; 00067 unsigned int pulsedur; 00068 unsigned int distance; 00069 }; 00070 00071 #endif
Generated on Sat Jul 16 2022 03:46:39 by
1.7.2
