Simple library for reading distance from SRF02 Ultrasonic Sensor in I2C mode.
Dependents: Project_A el13jarDistanceSensorProject UltrasonicDistanceSensor-el13jb Distance_Sensor_SRF02 ... more
Diff: SRF02.h
- Revision:
- 2:cb489f486ece
- Parent:
- 1:8e6587d88773
--- a/SRF02.h Sun Mar 08 14:21:40 2015 +0000 +++ b/SRF02.h Wed Jun 22 15:49:12 2016 +0000 @@ -8,10 +8,6 @@ #ifndef SRF02_H #define SRF02_H -// addresses -#define SRF02_R_ADD 0xE1 -#define SRF02_W_ADD 0xE0 - // registers #define CMD_REG 0x00 #define RANGE_H_REG 0x02 @@ -28,16 +24,18 @@ @brief Library for interfacing with SRF02 Ultrasonic Sensor in I2C @see http://www.robot-electronics.co.uk/htm/srf02tech.htm -@brief Revision 1.0 +@brief Revision 1.1 @author Craig A. Evans -@date March 2014 +@date June 2016 * * Example: * @code #include "mbed.h" #include "SRF02.h" + + SRF02 sensor(p28,p27,0xE0); // SDA, SCL, address int main() { @@ -62,15 +60,22 @@ * * @param sdaPin - mbed SDA pin * @param sclPin - mbed SCL pin + * @param addr - write address of the SRF02 sensor * */ - SRF02(PinName sdaPin, PinName sclPin); + SRF02(PinName sdaPin, PinName sclPin, char addr); /** Read distance in centimetres * * @returns distance in centimetres (int) * */ int getDistanceCm(); + /** Change I2C address of SRF02 sensor + * + * @param address - @see https://www.robot-electronics.co.uk/htm/srf02techI2C.htm for valid addresses + * + */ + void changeAddress(char addr); private: /** Hangs in infinite loop flashing 'blue lights of death' @@ -82,6 +87,9 @@ private: // private variables I2C* i2c; BusOut* leds; + + char w_addr_; // write address of sensor + char r_addr_; // read address (= write address + 1) }; #endif \ No newline at end of file