Exercise VL53L0X
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "VL53L0X.h" 00003 00004 /* This example shows how to use continuous mode to take 00005 range measurements with the VL53L0X. It is based on 00006 vl53l0x_ContinuousRanging_Example.c from the VL53L0X API. 00007 The range readings are in units of mm. */ 00008 00009 00010 Serial pc(SERIAL_TX, SERIAL_RX); 00011 00012 DigitalInOut sda_D(PB_9); 00013 DigitalInOut scl_D(PB_8); 00014 00015 // mbed uses 8bit addresses shift address by 1 bit left 00016 VL53L0X sensor_D(PB_9, PB_8); 00017 00018 00019 int main() { 00020 pc.baud(115200); 00021 00022 wait_ms(100); // delay .1s 00023 pc.printf("starting continuous\n"); 00024 sda_D.mode(PullUp); 00025 scl_D.mode(PullUp); 00026 //sensor_D.getIdentification(&identification); // Retrieve manufacture info from device memory 00027 //printIdentification(&identification); // Helper function to print all the Module information 00028 00029 sensor_D.init(); 00030 sensor_D.setTimeout(500); 00031 00032 // Start continuous back-to-back mode (take readings as 00033 // fast as possible). To use continuous timed mode 00034 // instead, provide a desired inter-measurement period in 00035 // ms (e.g. sensor.startContinuous(100)). 00036 sensor_D.startContinuous(50); 00037 while(1) { 00038 pc.printf("range = %d\n",sensor_D.readRangeContinuousMillimeters()); 00039 // if (sensor_D.timeoutOccurred()) { printf(" TIMEOUT\n"); } 00040 } 00041 }
Generated on Wed Jul 13 2022 15:17:10 by
1.7.2
Ian Kilburn