zockerlein

Untitled

Mar 8th, 2020
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. /*
  2. This example shows how to take simple range measurements with the VL53L1X. The
  3. range readings are in units of mm.
  4. */
  5.  
  6. #include <Wire.h>
  7. #include <VL53L1X.h>
  8.  
  9. VL53L1X sensor;
  10.  
  11. void setup()
  12. {
  13.   Serial.begin(115200);
  14.   Wire.begin();
  15.   Wire.setClock(400000); // use 400 kHz I2C
  16.  
  17.   sensor.setTimeout(500);
  18.   if (!sensor.init())
  19.   {
  20.     Serial.println("Failed to detect and initialize sensor!");
  21.     while (1);
  22.   }
  23.  
  24.   // Use long distance mode and allow up to 50000 us (50 ms) for a measurement.
  25.   // You can change these settings to adjust the performance of the sensor, but
  26.   // the minimum timing budget is 20 ms for short distance mode and 33 ms for
  27.   // medium and long distance modes. See the VL53L1X datasheet for more
  28.   // information on range and timing limits.
  29.   sensor.setDistanceMode(VL53L1X::Long);
  30.   sensor.setMeasurementTimingBudget(50000);
  31.  
  32.   // Start continuous readings at a rate of one measurement every 50 ms (the
  33.   // inter-measurement period). This period should be at least as long as the
  34.   // timing budget.
  35.   sensor.startContinuous(50);
  36. }
  37.  
  38. void loop()
  39. {
  40.   Serial.print(sensor.read());
  41.   if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
  42.  
  43.   Serial.println();
  44. }
Advertisement
Add Comment
Please, Sign In to add comment