This is a library that makes VL53L0X easy to handle.
# Example
include the mbed library with this snippet
#include "mbed.h" #include "TI_VL53L0X.h" DigitalOut led1(LED1); DigitalIn button(p11); TI_VL53L0X vl53l0x; int main() { led1 = 0; vl53l0x.setup(); vl53l0x.calibration(); while (true) { if (led1) { int averageRange = vl53l0x.getMeasurement(); if (9999 != averageRange) { printf("VL53L0X measurement average %d\n", averageRange); if (averageRange > 300) { led1 = 0; } else { led1 = 1; } } } if (button) { printf("Button Pressed\n\r"); wait(0.7); led1 = !led1; if (led1) { vl53l0x.startMeasurement(); } else { vl53l0x.stopMeasurement(); } } } }
TI_VL53L0X.h@0:9d485cd4147c, 2018-06-05 (annotated)
- Committer:
- tichise
- Date:
- Tue Jun 05 15:52:04 2018 +0000
- Revision:
- 0:9d485cd4147c
new;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tichise | 0:9d485cd4147c | 1 | #ifndef MBED_TI_VL53L0X_H |
tichise | 0:9d485cd4147c | 2 | #define MBED_TI_VL53L0X_H |
tichise | 0:9d485cd4147c | 3 | |
tichise | 0:9d485cd4147c | 4 | #include "mbed.h" |
tichise | 0:9d485cd4147c | 5 | #include "vl53l0x_api.h" |
tichise | 0:9d485cd4147c | 6 | #include "vl53l0x_i2c_platform.h" |
tichise | 0:9d485cd4147c | 7 | #include "vl53l0x_platform.h" |
tichise | 0:9d485cd4147c | 8 | |
tichise | 0:9d485cd4147c | 9 | /** |
tichise | 0:9d485cd4147c | 10 | * LPC1768用 |
tichise | 0:9d485cd4147c | 11 | */ |
tichise | 0:9d485cd4147c | 12 | class TI_VL53L0X |
tichise | 0:9d485cd4147c | 13 | { |
tichise | 0:9d485cd4147c | 14 | public: |
tichise | 0:9d485cd4147c | 15 | TI_VL53L0X(); |
tichise | 0:9d485cd4147c | 16 | |
tichise | 0:9d485cd4147c | 17 | void printPalState(VL53L0X_State state); |
tichise | 0:9d485cd4147c | 18 | void printPalError(VL53L0X_Error status); |
tichise | 0:9d485cd4147c | 19 | void printRangeStatus( |
tichise | 0:9d485cd4147c | 20 | VL53L0X_RangingMeasurementData_t *pRangingMeasurementData); |
tichise | 0:9d485cd4147c | 21 | VL53L0X_Error waitMeasurementDataReady(VL53L0X_DEV dev); |
tichise | 0:9d485cd4147c | 22 | VL53L0X_Error waitStopCompleted(VL53L0X_DEV dev); |
tichise | 0:9d485cd4147c | 23 | |
tichise | 0:9d485cd4147c | 24 | void setup(); |
tichise | 0:9d485cd4147c | 25 | void calibration(); |
tichise | 0:9d485cd4147c | 26 | void stopMeasurement(); |
tichise | 0:9d485cd4147c | 27 | void startMeasurement(); |
tichise | 0:9d485cd4147c | 28 | int getMeasurement(); |
tichise | 0:9d485cd4147c | 29 | |
tichise | 0:9d485cd4147c | 30 | private: |
tichise | 0:9d485cd4147c | 31 | VL53L0X_State apiState; |
tichise | 0:9d485cd4147c | 32 | VL53L0X_Error status; |
tichise | 0:9d485cd4147c | 33 | VL53L0X_Dev_t myDevice; |
tichise | 0:9d485cd4147c | 34 | VL53L0X_Dev_t *pMyDevice; |
tichise | 0:9d485cd4147c | 35 | }; |
tichise | 0:9d485cd4147c | 36 | |
tichise | 0:9d485cd4147c | 37 | #endif |
tichise | 0:9d485cd4147c | 38 |