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.
SRF08.h
00001 /* 00002 Copyright (c) 2012 Brent Dekker 00003 00004 Permission is hereby granted, free of charge, to any person obtaining a copy 00005 of this software and associated documentation files (the "Software"), to deal 00006 in the Software without restriction, including without limitation the rights 00007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00008 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 00012 all copies or substantial portions of the Software. 00013 00014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00015 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00016 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00017 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00018 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00019 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00020 THE SOFTWARE. 00021 */ 00022 00023 #ifndef SRF08_H 00024 #define SRF08_H 00025 00026 #include "mbed.h" 00027 #include "rtos.h" 00028 00029 /** 00030 * The SRF08 is an ultrasonic range finder with an I2C interface that allows 00031 * the measurement to be read directly in centimetres. More information can be 00032 * found on this website: http://www.robot-electronics.co.uk/htm/srf08tech.shtml 00033 */ 00034 class SRF08 { 00035 00036 public: 00037 00038 /** 00039 * Create a SRF08 object connected to the specified I2C pins and address 00040 * 00041 * @param SDA I2C SDA pin to connect to 00042 * @param SCL I2C SCL pin to connect to 00043 * @param i2cAddress Address of WSRF08 on I2C bus 00044 */ 00045 SRF08(PinName SDA, PinName SCL, int i2cAddress); 00046 00047 /** 00048 * Send the "Start ranging in cm" command via I2C 00049 */ 00050 void startRanging(); 00051 00052 /** 00053 * Checks if the module has finished ranging 00054 * 00055 * @param returns Boolean stating module is finished or not 00056 */ 00057 bool rangingFinished(); 00058 00059 /** 00060 * Gets the measured range from the module 00061 * 00062 * @param returns Integer range in centimetre 00063 */ 00064 int getRange(); 00065 00066 /** 00067 * Gets the measured light intensity from the module 00068 * 00069 * @param returns A normalised number 0-255 representing dark to light 00070 */ 00071 int getLightIntensity(); 00072 00073 /** 00074 * Sets the range register of the SRF08 for faster ranging. 00075 * 00076 * The max range is ((rangeVal x 43mm) + 43mm). The sensors maximum range 00077 * is about six metres 00078 * 00079 * @param rangeVal The value written to the range register of the SRF08 00080 */ 00081 void setRangeRegister(unsigned char rangeVal); 00082 00083 /** 00084 * Sets the max gain register of the SRF08. 00085 * 00086 * @param gainVal The value written to the max gain register of the SRF08 00087 */ 00088 void setMaxGainRegister(unsigned char gainVal); 00089 00090 /** 00091 * Changes the I2C address of the SRF08. 00092 * 00093 * The factory default address is 0x0E (224) 00094 * The address can have the following values: 00095 * E0 | E2 | E4 | E6 ... FC | FE 00096 * 00097 * @param i2cAddress The new I2C address for the SRF08. 00098 */ 00099 void setAddress(int i2cAddress); 00100 00101 protected: 00102 00103 I2C i2cMod; 00104 unsigned char i2cAddress; 00105 bool rangingBusy; 00106 00107 void setRangingFinished(); 00108 }; 00109 00110 #endif
Generated on Mon Jul 18 2022 05:41:29 by
