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.
SRF02.h
00001 /* mbed SRF02 Ultra Sonic Range Finder Library 00002 * Copyright (c) 2011 by djoshi [go2dev] 00003 * Permission is hereby granted, free of charge, to any person obtaining a copy 00004 * of this software and associated documentation files (the "Software"), to deal 00005 * in the Software without restriction, including without limitation the rights 00006 *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00007 *copies of the Software, and to permit persons to whom the Software is 00008 *furnished to do so, subject to the following conditions: 00009 * 00010 *The above copyright notice and this permission notice shall be included in 00011 *all copies or substantial portions of the Software. 00012 * 00013 *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00014 *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00015 *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00016 *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00017 *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00018 *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00019 *THE SOFTWARE. 00020 */ 00021 00022 00023 /*Header file for the SRF02 sonar range finder class*/ 00024 #ifndef SRF02_H 00025 #define SRF02_H 00026 00027 #include "mbed.h" 00028 00029 //!Library for the SRF02 Ultrasonic Ranger 00030 /* 00031 * The SRF02 is an I2C Ultrasonic rangefinder which can return values for measured 00032 * distance as either time of flight (uS) or directly in cm or in. 00033 00034 * Example Usage: 00035 * @code 00036 * //Take a measurement of the current distance (in cm), print the result to the terminal via the debug port 00037 * #include "mbed.h" 00038 * #include "SRF02.h" 00039 * 00040 * Serial debugport(USBTX,USBRX); 00041 * SRF02 mySensor(p9,p10,0xE0); 00042 * main() { 00043 * while (1) { 00044 * debugport.printf("current distance: %.2f cm. \r\n", mySensor.measurecm()); 00045 * } 00046 * } 00047 * @endcode 00048 */ 00049 00050 */ 00051 00052 class SRF02 { 00053 public: 00054 /** Create a SRF02 object connected to the specified I2C pins 00055 * 00056 * @param sda I2C Data pin to connect to 00057 * @param scl I2C Clock pin to connect to 00058 */ 00059 SRF02(PinName sda, PinName scl, int addr); 00060 00061 /** Destroys an instance of SRD02 00062 */ 00063 ~SRF02(); 00064 00065 /** Get the current distance in centimetres 00066 * 00067 * @param returns the measured distance in centimetres as a float 00068 */ 00069 float measurecm(); 00070 00071 /** Get the current distance in centimetres 00072 * 00073 * @param returns the measured distance in inches as a float 00074 */ 00075 float measurein(); 00076 00077 /** Get the current distance in centimetres 00078 * 00079 * @param returns the time of flight from the pulse sent from the sensor in microseconds (uS) as a float 00080 */ 00081 float measureus(); 00082 00083 00084 private: 00085 I2C m_i2c; 00086 int m_addr; 00087 00088 /** dosonar is an internal function for this library which actually manages the I2C transaction with the sensor to get a reading. 00089 * It is not directly accessible by the user via the libaray 00090 */ 00091 float dosonar(char rangetype); 00092 00093 00094 }; 00095 #endif
Generated on Fri Jul 15 2022 19:17:58 by
1.7.2