/* This code is based on example that shows how to take simple range measurements with the VL53L1X. The range readings are in units of mm. */ #include #include VL53L1X sensor; void setup() { Serial.begin(115200); Wire.begin(); // Start I2C Wire.setClock(400000); // use Fast-mode (Fm) sensor.setTimeout(500); // Default timeout if (!sensor.init()) { Serial.println("Sensor not found!"); while (1); // Don't proceed to trying to use non-present sensor } // Using long distance mode allows up to 50000 us (50 ms) for a measurement. // These settings adjust the performance of the sensor. // Minimum time values: // Short distance mode 20 ms // Medium & Long modes 33 ms sensor.setDistanceMode(VL53L1X::Long); sensor.setMeasurementTimingBudget(50000); // microseconds // Start continuous readings at a rate of one measurement every 50 ms (the // inter-measurement period). This period should be at least as long as the // timing budget. sensor.startContinuous(50); // milliseconds } void loop() { // Print sensor readings via Serial. Serial.print("VL53L1X reading: "); Serial.print(sensor.read()); if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); } Serial.println(); }