Exercise VL53L0X

Dependencies:   VL53L0X mbed

Committer:
highroads
Date:
Sun Feb 26 12:45:58 2017 +0000
Revision:
0:0b3a16f02de9
First version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
highroads 0:0b3a16f02de9 1 #include "mbed.h"
highroads 0:0b3a16f02de9 2 #include "VL53L0X.h"
highroads 0:0b3a16f02de9 3
highroads 0:0b3a16f02de9 4 /* This example shows how to use continuous mode to take
highroads 0:0b3a16f02de9 5 range measurements with the VL53L0X. It is based on
highroads 0:0b3a16f02de9 6 vl53l0x_ContinuousRanging_Example.c from the VL53L0X API.
highroads 0:0b3a16f02de9 7 The range readings are in units of mm. */
highroads 0:0b3a16f02de9 8
highroads 0:0b3a16f02de9 9
highroads 0:0b3a16f02de9 10 Serial pc(SERIAL_TX, SERIAL_RX);
highroads 0:0b3a16f02de9 11
highroads 0:0b3a16f02de9 12 DigitalInOut sda_D(PB_9);
highroads 0:0b3a16f02de9 13 DigitalInOut scl_D(PB_8);
highroads 0:0b3a16f02de9 14
highroads 0:0b3a16f02de9 15 // mbed uses 8bit addresses shift address by 1 bit left
highroads 0:0b3a16f02de9 16 VL53L0X sensor_D(PB_9, PB_8);
highroads 0:0b3a16f02de9 17
highroads 0:0b3a16f02de9 18
highroads 0:0b3a16f02de9 19 int main() {
highroads 0:0b3a16f02de9 20 pc.baud(115200);
highroads 0:0b3a16f02de9 21
highroads 0:0b3a16f02de9 22 wait_ms(100); // delay .1s
highroads 0:0b3a16f02de9 23 pc.printf("starting continuous\n");
highroads 0:0b3a16f02de9 24 sda_D.mode(PullUp);
highroads 0:0b3a16f02de9 25 scl_D.mode(PullUp);
highroads 0:0b3a16f02de9 26 //sensor_D.getIdentification(&identification); // Retrieve manufacture info from device memory
highroads 0:0b3a16f02de9 27 //printIdentification(&identification); // Helper function to print all the Module information
highroads 0:0b3a16f02de9 28
highroads 0:0b3a16f02de9 29 sensor_D.init();
highroads 0:0b3a16f02de9 30 sensor_D.setTimeout(500);
highroads 0:0b3a16f02de9 31
highroads 0:0b3a16f02de9 32 // Start continuous back-to-back mode (take readings as
highroads 0:0b3a16f02de9 33 // fast as possible). To use continuous timed mode
highroads 0:0b3a16f02de9 34 // instead, provide a desired inter-measurement period in
highroads 0:0b3a16f02de9 35 // ms (e.g. sensor.startContinuous(100)).
highroads 0:0b3a16f02de9 36 sensor_D.startContinuous(50);
highroads 0:0b3a16f02de9 37 while(1) {
highroads 0:0b3a16f02de9 38 pc.printf("range = %d\n",sensor_D.readRangeContinuousMillimeters());
highroads 0:0b3a16f02de9 39 // if (sensor_D.timeoutOccurred()) { printf(" TIMEOUT\n"); }
highroads 0:0b3a16f02de9 40 }
highroads 0:0b3a16f02de9 41 }