Here you go. I have no way to test this, so that's up to you. If there are problems, please give detailed description and include serial monitor output (not a picture, text, between code tags).
#include "Adafruit_VL53L0X.h"
#define LOX_COUNT 3
// address we will assign if dual sensor is present
const byte loxAddress[LOX_COUNT] = {0x30, 0x31, 0x32};
// set the pins to shutdown
const byte loxPin[LOX_COUNT] = {7, 6, 5};
// objects for the vl53l0x
Adafruit_VL53L0X lox[LOX_COUNT];
// this holds the measurement
VL53L0X_RangingMeasurementData_t measure[LOX_COUNT];
/*
Reset all sensors by setting all of their XSHUT pins low for delay(10), then set all XSHUT high to bring out of reset
Keep sensor #1 awake by keeping XSHUT pin high
Put all other sensors into shutdown by pulling XSHUT pins low
Initialize sensor #1 with lox.begin(new_i2c_address) Pick any number but 0x29 and it must be under 0x7F. Going with 0x30 to 0x3F is probably OK.
Keep sensor #1 awake, and now bring sensor #2 out of reset by setting its XSHUT pin high.
Initialize sensor #2 with lox.begin(new_i2c_address) Pick any number but 0x29 and whatever you set the first sensor to
*/
void setID() {
// all reset
for(byte i=0; i<LOX_COUNT; i++)
digitalWrite(loxPin[i], LOW);
delay(10);
// activating each LOX
for(byte i=0; i<LOX_COUNT; i++) {
lox[i] = Adafruit_VL53L0X();
digitalWrite(loxPin[i], HIGH);
// initing LOX
if(!lox[i].begin(loxAddress[i])) {
Serial.print(F("Failed to boot VL53L0X #"));
Serial.println(i);
while(1);
}
delay(10);
}
}
void read_sensors() {
// print sensor readings
for(byte i=0; i<LOX_COUNT; i++) {
lox[i].rangingTest(&measure[i], false); // pass in 'true' to get debug data printout!
Serial.print(i);
Serial.print(F(": "));
if(measure[i].RangeStatus != 4) { // if not out of range
Serial.print(measure[i].RangeMilliMeter);
} else {
Serial.print(F("Out of range"));
}
Serial.print(F(" "));
}
Serial.println();
}
void setup() {
Serial.begin(115200);
// wait until serial port opens for native USB devices
while (! Serial) { delay(1); }
for(byte i=0; i<LOX_COUNT; i++)
pinMode(loxPin[i], OUTPUT);
Serial.println(F("Shutdown pins inited..."));
Serial.println(F("Starting..."));
setID();
}
void loop() {
read_sensors();
delay(100);
}