IUT CACHAN pour Yves GUINAND

Fork of VL6180 by Steven Burg

Committer:
PierreolivierKOENIG
Date:
Tue Jun 12 14:48:03 2018 +0000
Revision:
4:c4f807009044
Parent:
2:595673e4c505
v

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sburg 0:f23c00f688b2 1 #ifndef MBED_VL6180_H
sburg 0:f23c00f688b2 2 #define MBED_VL6180_H
sburg 0:f23c00f688b2 3
sburg 0:f23c00f688b2 4 #include "mbed.h"
sburg 2:595673e4c505 5 /** VL6180 control class.
sburg 2:595673e4c505 6 *
sburg 2:595673e4c505 7 * Example:
sburg 2:595673e4c505 8 * @code
sburg 2:595673e4c505 9 * //Update pc terminal every half second with range reading
sburg 2:595673e4c505 10 * #include "VL6180.h"
sburg 2:595673e4c505 11 * #include "mbed.h"
sburg 2:595673e4c505 12 *
sburg 2:595673e4c505 13 * VL6180 rf(p9, p10); //I2C sda and scl
sburg 2:595673e4c505 14 * Serial pc(USBTX, USBRX); //USB serial
sburg 2:595673e4c505 15 *
sburg 2:595673e4c505 16 * int main() {
sburg 2:595673e4c505 17 * float reading;
sburg 2:595673e4c505 18 * while(1) {
sburg 2:595673e4c505 19 * reading = rf;
sburg 2:595673e4c505 20 * pc.printf("Read %4.1f cm\n", reading);
sburg 2:595673e4c505 21 * wait(0.5);
sburg 2:595673e4c505 22 * }
sburg 2:595673e4c505 23 * }
sburg 2:595673e4c505 24 * @endcode
sburg 2:595673e4c505 25 */
sburg 0:f23c00f688b2 26 class VL6180 {
sburg 0:f23c00f688b2 27 public:
sburg 0:f23c00f688b2 28 /** Create a VL6180 object at I2C address 0x29 (7 bit).
sburg 0:f23c00f688b2 29 *
sburg 0:f23c00f688b2 30 * @param sda I2C sda pin number
sburg 0:f23c00f688b2 31 * @param scl I2C scl pin number
sburg 0:f23c00f688b2 32 */
sburg 0:f23c00f688b2 33 VL6180(PinName sda, PinName scl);
sburg 0:f23c00f688b2 34
sburg 0:f23c00f688b2 35 /** Make a range reading.
sburg 0:f23c00f688b2 36 *
sburg 0:f23c00f688b2 37 * @param return Distance to target in cm. Approx 0.0 cm to 20.0 cm.
sburg 0:f23c00f688b2 38 */
sburg 0:f23c00f688b2 39 float read();
PierreolivierKOENIG 4:c4f807009044 40
sburg 1:1b46b69895f9 41 /** Float cast is shorthand for read() */
sburg 0:f23c00f688b2 42 operator float();
sburg 0:f23c00f688b2 43
sburg 0:f23c00f688b2 44 private:
sburg 0:f23c00f688b2 45 void writeI2C(int reg, char data);
sburg 0:f23c00f688b2 46 char readI2C(int reg);
sburg 0:f23c00f688b2 47 I2C _i2c;
sburg 0:f23c00f688b2 48 int _res;
sburg 0:f23c00f688b2 49 static const int _addr = 0x52;
sburg 0:f23c00f688b2 50 };
sburg 0:f23c00f688b2 51
sburg 0:f23c00f688b2 52 #endif