Simple library for reading distance from SRF02 Ultrasonic Sensor in I2C mode.
Dependents: Project_A el13jarDistanceSensorProject UltrasonicDistanceSensor-el13jb Distance_Sensor_SRF02 ... more
SRF02 Class Reference
Library for interfacing with SRF02 Ultrasonic Sensor in I2C. More...
#include <SRF02.h>
Public Member Functions | |
SRF02 (PinName sdaPin, PinName sclPin, char addr) | |
Create a SRF02 object connected to the specified I2C pins. | |
int | getDistanceCm () |
Read distance in centimetres. | |
void | changeAddress (char addr) |
Change I2C address of SRF02 sensor. |
Detailed Description
Library for interfacing with SRF02 Ultrasonic Sensor in I2C.
Revision 1.1
- Date:
- June 2016
Example:
#include "mbed.h" #include "SRF02.h" SRF02 sensor(p28,p27,0xE0); // SDA, SCL, address int main() { while(1) { // read sensor distance in cm and print over serial port int distance = sensor.getDistanceCm(); serial.printf("Distance = %d cm\n",distance); // short delay before next measurement wait(0.5); } }
Definition at line 55 of file SRF02.h.
Constructor & Destructor Documentation
SRF02 | ( | PinName | sdaPin, |
PinName | sclPin, | ||
char | addr | ||
) |
Member Function Documentation
void changeAddress | ( | char | addr ) |
Change I2C address of SRF02 sensor.
- Parameters:
-
address -
- See also:
- https://www.robot-electronics.co.uk/htm/srf02techI2C.htm for valid addresses
Generated on Wed Jul 13 2022 17:49:25 by 1.7.2