Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "VL53L0X.h" 00002 #include "mbed.h" 00003 00004 DevI2C i2C(PB_9, PB_8); 00005 DigitalOut Pin_Out(PB_9); 00006 VL53L0X capteur(&i2C, &Pin_Out, PA_8, VL53L0X_DEFAULT_ADDRESS); 00007 VL53L0X_Dev_t MyDevice; 00008 VL53L0X_Dev_t *pMyDevice = &MyDevice; 00009 int distance(uint32_t *p_data); 00010 00011 int main(){ 00012 uint32_t status = 0; 00013 uint32_t *dist; 00014 00015 printf("\n\r"); 00016 printf("\n\r"); 00017 //pMyDevice->comms_type = 1; 00018 //pMyDevice->comms_speed_khz = 400; 00019 00020 capteur.init_sensor(VL53L0X_DEFAULT_ADDRESS); 00021 //capteur.disable_interrupt_measure_detection_irq(); 00022 while(1){ 00023 status = distance(dist); 00024 printf("Distance : %d mm\n\r", *dist); 00025 printf("Statut : %d \n\r", status); 00026 printf("\n"); 00027 wait(0.2); 00028 } 00029 capteur.VL53L0X_off(); 00030 } 00031 00032 int distance(uint32_t *p_data){ 00033 int status = 0; 00034 VL53L0X_RangingMeasurementData_t measurement_data; 00035 00036 status = capteur.start_measurement(range_single_shot_polling, NULL); 00037 if (!status) { 00038 status = capteur.get_measurement(range_single_shot_polling, &measurement_data); 00039 } 00040 if (measurement_data.RangeStatus == 0) { 00041 *p_data = measurement_data.RangeMilliMeter; 00042 } else { 00043 *p_data = 0; 00044 status = VL53L0X_ERROR_RANGE_ERROR; 00045 } 00046 capteur.stop_measurement(range_single_shot_polling); 00047 return status; 00048 }
Generated on Thu Jul 21 2022 02:41:56 by
1.7.2