Library for interfacing the SRF08 ultrasonic range sensor. Most functions of the SRF08 are covered, including interrupt-based waiting for the ranging process to finish

Dependents:   Project6

Fork of SRF08 by Brent Dekker

SRF08.h

Committer:
brentdekker
Date:
2012-07-05
Revision:
0:4e0a8193b92e
Child:
1:76fb116fa28d

File content as of revision 0:4e0a8193b92e:


/*
Copyright (c) 2010 Chris Styles (chris dot styles at mbed dot org)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#ifndef SRF08_H
#define SRF08_H

#include "mbed.h"

/*
 * The SRF08 is an Ultrasonic range finder, with an I2C interface that allows the measurement to be read directly in centimetres
 */
class SRF08 {

public:

    /*
     * Constructor: SRF08
     * Args:        PinName sda: Data pin of I2C bus to which module is connected
     *              PinName scl: Clock pin of I2C bus to which module is connected
     *              int addr:    address of module on the I2C bus
     * Returns:     void
     * Description: Creates an instance of the SRF08 to communicate with a sRF08 module
     */
    SRF08(PinName sda, PinName scl, int addr);

    /*
     * Destructor:  ~SRF08
     * Args:        void
     * Returns:     void
     * Description: Destroys instance of SRF08 class
     */
    ~SRF08();

    /*
     * Function:    readRange
     * Args:        void
     * Returns:     int range
     * Description: Reads the range register and converts it to a usable value
     */
    int read();
    
    /*
     * Function:    readLightIntensity
     * Args:        void
     * Returns:     int lightIntensity
     * Description: Reads the lightIntensity from the module
     */
     int readLightIntensity();
     
    /*
     * Function:    setRangeRegister
     * Args:        rangeVal
     * Returns:     void
     * Description: Sets the maximum range for which the module waits for an echo
     *              The range is ((rangeVal x 43mm) + 43mm)
     *              The max range is about six meters
     */
    void setRangeRegister(char rangeVal);
    
    /*
     * Function:    setAddress
     * Args:        address
     * Returns:     void
     * Description: Sets the address of the module on the I2C bus. The factory default address is 0x0E (224)
     *              The address can have the following values:
     *                 E0 | E2 | E4 | E6 ... FC | FE
     */
    void setAddress(char address);
     
private:
    I2C m_i2c;
    int m_addr;

};

#endif