version for edu_robot TM

Dependents:   EduRobot

Fork of SRF02 by Roberto D'Amico

Embed: (wiki syntax)

« Back to documentation index

SRF02 Class Reference

SRF02 Class Reference

Library for the SRF02 Ultrasonic Ranger Sensor, using the I2C bus for the comunication. More...

#include <SRF02.h>

Public Member Functions

 SRF02 (PinName sda, PinName scl, int addr, char type)
 Creates an instance of class.
float read ()
 Start and return the range measure.

Detailed Description

Library for the SRF02 Ultrasonic Ranger Sensor, using the I2C bus for the comunication.

Remeber that sensor can function in serial mode if MODE pin is connected to the ground, but this libary not support this mode.

Example:

  // Continuously measuring range
  #include "mbed.h"
  #include "SRF02.h"
  // Create instance of class SRF02 for device at address 0xE0 and take mesure in cm
  SRF02 srf02(p28, p27, 0xE0, 0x51);
  DigitalOut led1(LED1);
 
  int main() 
  {
      led1=1;
      while(1)
      {
          printf("Measured range : %.2f cm\n\r",srf02.read());
          wait(0.5);
          led1=!led1;
      }
  }

Definition at line 56 of file SRF02.h.


Constructor & Destructor Documentation

SRF02 ( PinName  sda,
PinName  scl,
int  addr,
char  type 
)

Creates an instance of class.

Setting the pin used for I2C, the address of device and the measure range type.

Parameters:
sdaA pin used for SDA I2C signal.
sclA pin used for SCL I2C signal.
addrThe address of I2C SRF02 device.
measure_typeThe of mesure response (0x50-inches,0x51-centimeters,0x52-micro-seconds).

Definition at line 4 of file SRF02.cpp.


Member Function Documentation

float read (  )

Start and return the range measure.

Returns:
The value of measure.

Definition at line 17 of file SRF02.cpp.