A demonstration program to show the use of a VL53L3CX ToF sensor on a F401 board with a x-nucleo shield. Uses Ranging library. Mbed 6.
Diff: main.cpp
- Revision:
- 2:0ea3b4cbcfd1
- Parent:
- 1:996154b22d5b
- Child:
- 3:35a4659d0ae4
diff -r 996154b22d5b -r 0ea3b4cbcfd1 main.cpp --- a/main.cpp Tue Jul 20 15:12:06 2021 +0000 +++ b/main.cpp Wed Jul 21 09:33:43 2021 +0000 @@ -86,6 +86,8 @@ RANGING_SENSOR_Result_t Result; RANGING_SENSOR_ProfileConfig_t Profile; + uint16_t target = 0; + uint16_t zone = 0; // vl53l3cx has 1 zone printf("MX_53L3A2_MultiSensorRanging_Process\n"); Profile.RangingProfile = RS_MULTI_TARGET_LONG_RANGE; @@ -111,16 +113,24 @@ printf("MX_53L3A2_MultiSensorRanging_Process read sensors\n"); // repeatedly read data and start next measurement + // Note in VL53L3CX there is only one Zone so NumberOfZones is not used and is always assumed to be 1 while (1) { memset( &Result, 0x0,sizeof(RANGING_SENSOR_Result_t)); status = sensor->VL53L3A2_RANGING_GetDistance(ToF_sensor, &Result); if ((status == BSP_ERROR_NONE) && - ( Result.NumberOfZones != 0) && - (Result.ZoneResult[0].Status[0] == BSP_ERROR_NONE )) { - printf("\n |---> "); - printf("Status = %d, Distance = %5d mm", - Result.ZoneResult[0].Status[0], - Result.ZoneResult[0].Distance[0]); + ( Result.ZoneResult[zone].NumberOfTargets != 0)) + { + for ( target = 0 ; target < Result.ZoneResult[0].NumberOfTargets; target++) + { + if (Result.ZoneResult[zone].Status[0] == VL53LX_RANGESTATUS_RANGE_VALID ) + { + printf("\n |---> "); + printf("Status = %d, Target %d, Distance = %5d mm", + Result.ZoneResult[zone].Status[target], + target, + Result.ZoneResult[zone].Distance[target]); + } + } } wait_ms(POLLING_PERIOD);