Library for the VL6180 time of flight range finder.

Dependents:   VL6180_Hello_World STM32F103C8T6_VL6180 BLE_Sensor_VL6180 BLE_Sensor_VL6180_window

VL6180.h

Committer:
sburg
Date:
2015-10-19
Revision:
3:5d61f202b1bd
Parent:
2:595673e4c505

File content as of revision 3:5d61f202b1bd:

#ifndef MBED_VL6180_H
#define MBED_VL6180_H

#include "mbed.h"
/** VL6180 control class.
 *
 * Example:
 * @code
 * //Update pc terminal every half second with range reading
 * #include "VL6180.h"
 * #include "mbed.h"
 *
 * VL6180 rf(p9, p10); //I2C sda and scl
 * Serial pc(USBTX, USBRX); //USB serial
 *
 * int main() {
 *   float reading;
 *   while(1) {
 *      reading = rf;
 *      pc.printf("Read %4.1f cm\n", reading);
 *      wait(0.5);
 *  }
 * }
 * @endcode
 */
class VL6180 {
public:
    /** Create a VL6180 object at I2C address 0x29 (7 bit).
     * 
     * @param sda I2C sda pin number
     * @param scl I2C scl pin number
     */
    VL6180(PinName sda, PinName scl);
    
    /** Make a range reading.
     * 
     * @param return Distance to target in cm. Approx 0.0 cm to 20.0 cm.
     */
    float read();
    
    /** Float cast is shorthand for read() */
    operator float();
    
private:
    void writeI2C(int reg, char data);
    char readI2C(int reg);
    I2C _i2c;
    int _res;
    static const int _addr = 0x52;
};

#endif