version for edu_robot TM

Dependents:   EduRobot

Fork of SRF02 by Roberto D'Amico

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SRF02.h Source File

SRF02.h

00001 /* mbed SRF02 Ultrasonic Ranger Sensor Library
00002  * Created by bobboteck at 16/11/2011
00003  *
00004  * Based on: Chris Styles [http://mbed.org/users/chris/] Library for SRF08 
00005  *           "http://mbed.org/users/chris/programs/SRF08/603nk/docs/"
00006  *
00007  * Permission is hereby granted, free of charge, to any person obtaining a copy
00008  * of this software and associated documentation files (the "Software"), to deal
00009  * in the Software without restriction, including without limitation the rights
00010  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00011  * copies of the Software, and to permit persons to whom the Software is
00012  * furnished to do so, subject to the following conditions:
00013  *
00014  * The above copyright notice and this permission notice shall be included in
00015  * all copies or substantial portions of the Software.
00016  *
00017  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00020  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00021  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00022  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00023  * THE SOFTWARE.
00024  */
00025 
00026 #ifndef SRF02_H
00027 #define SRF02_H
00028 
00029 #include "mbed.h"
00030 
00031 /** Library for the SRF02 Ultrasonic Ranger Sensor, using the I2C bus for the
00032  * comunication. Remeber that sensor can function in serial mode if MODE pin
00033  * is connected to the ground, but this libary not support this mode.
00034  *
00035  * Example:
00036  * @code
00037  *  // Continuously measuring range
00038  *  #include "mbed.h"
00039  *  #include "SRF02.h"
00040  *  // Create instance of class SRF02 for device at address 0xE0 and take mesure in cm
00041  *  SRF02 srf02(p28, p27, 0xE0, 0x51);
00042  *  DigitalOut led1(LED1);
00043  * 
00044  *  int main() 
00045  *  {
00046  *      led1=1;
00047  *      while(1)
00048  *      {
00049  *          printf("Measured range : %.2f cm\n\r",srf02.read());
00050  *          wait(0.5);
00051  *          led1=!led1;
00052  *      }
00053  *  }
00054  * @endcode
00055  */
00056 class SRF02
00057 {
00058     public:
00059         //enum _typem{INCHES=0x050,CENTIMETERS=0x51,MICROSECONDS=0x52};
00060         /** Creates an instance of class. Setting the pin used for I2C, the address of device and the measure range type.
00061          *
00062          * @param sda A pin used for SDA I2C signal.
00063          * @param scl A pin used for SCL I2C signal.
00064          * @param addr The address of I2C SRF02 device.
00065          * @param measure_type The of mesure response (0x50-inches,0x51-centimeters,0x52-micro-seconds).
00066          */
00067         SRF02(PinName sda, PinName scl, int addr, char type);
00068       
00069         /* Destroyer of class instance. */
00070         ~SRF02();
00071       
00072         /** Start and return the range measure.
00073          *
00074          * @returns The value of measure.
00075          */
00076         float read();
00077       
00078     private:
00079         I2C _i2c;      // I2C object to comunicate with SRF02
00080         int _addr;     // Address of sensor
00081         char _typem;   // Type of mesure
00082 };
00083 
00084 #endif