Christian Benitez
/
VL53L1X__
No range status update (error 255)
Fork of VL53L1X by
main.cpp@4:a9362bc0597a, 2018-07-24 (annotated)
- Committer:
- cpbenite
- Date:
- Tue Jul 24 17:41:28 2018 +0000
- Revision:
- 4:a9362bc0597a
No range status update
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cpbenite | 4:a9362bc0597a | 1 | #include "mbed.h" |
cpbenite | 4:a9362bc0597a | 2 | #include "VL53L1X.h" |
cpbenite | 4:a9362bc0597a | 3 | |
cpbenite | 4:a9362bc0597a | 4 | VL53L1X L(D14, D15); |
cpbenite | 4:a9362bc0597a | 5 | Serial pc(USBTX, USBRX); |
cpbenite | 4:a9362bc0597a | 6 | |
cpbenite | 4:a9362bc0597a | 7 | int main(){ |
cpbenite | 4:a9362bc0597a | 8 | uint16_t d, sr; |
cpbenite | 4:a9362bc0597a | 9 | uint8_t rs; |
cpbenite | 4:a9362bc0597a | 10 | int r; |
cpbenite | 4:a9362bc0597a | 11 | // LED1 will blink if returns wrong Model ID |
cpbenite | 4:a9362bc0597a | 12 | // Blinking LED2 related to firmware |
cpbenite | 4:a9362bc0597a | 13 | while (L.begin() == false){ |
cpbenite | 4:a9362bc0597a | 14 | pc.printf("Sensor offline!\n"); |
cpbenite | 4:a9362bc0597a | 15 | wait_ms(10); |
cpbenite | 4:a9362bc0597a | 16 | } |
cpbenite | 4:a9362bc0597a | 17 | |
cpbenite | 4:a9362bc0597a | 18 | pc.printf("Sensor online!\n"); |
cpbenite | 4:a9362bc0597a | 19 | L.newDataReady(); |
cpbenite | 4:a9362bc0597a | 20 | |
cpbenite | 4:a9362bc0597a | 21 | while(1){ |
cpbenite | 4:a9362bc0597a | 22 | L.softReset(); |
cpbenite | 4:a9362bc0597a | 23 | r = L.newDataReady(); |
cpbenite | 4:a9362bc0597a | 24 | |
cpbenite | 4:a9362bc0597a | 25 | if(r){ |
cpbenite | 4:a9362bc0597a | 26 | L.setDistanceMode(2); |
cpbenite | 4:a9362bc0597a | 27 | d = L.getDistance(); |
cpbenite | 4:a9362bc0597a | 28 | sr = L.getSignalRate(); |
cpbenite | 4:a9362bc0597a | 29 | rs = L.getRangeStatus(); |
cpbenite | 4:a9362bc0597a | 30 | pc.printf("newDataReady?: %d, Distance (mm): %d, SignalRate: %d, RangeStatus: %d\n", r, d, sr, rs); |
cpbenite | 4:a9362bc0597a | 31 | } |
cpbenite | 4:a9362bc0597a | 32 | |
cpbenite | 4:a9362bc0597a | 33 | wait_ms(500); |
cpbenite | 4:a9362bc0597a | 34 | } |
cpbenite | 4:a9362bc0597a | 35 | |
cpbenite | 4:a9362bc0597a | 36 | } |