File tree Expand file tree Collapse file tree 5 files changed +25
-5
lines changed
Example4_SetIntermeasurementPeriod Expand file tree Collapse file tree 5 files changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,11 @@ void setup(void)
4646void loop (void )
4747{
4848 distanceSensor.startRanging (); // Write configuration bytes to initiate measurement
49+ while (!distanceSensor.checkForDataReady ()) {
50+ delay (1 );
51+ }
4952 int distance = distanceSensor.getDistance (); // Get the result of the measurement from the sensor
53+ distanceSensor.clearInterrupt ();
5054 distanceSensor.stopRanging ();
5155
5256 Serial.print (" Distance(mm): " );
Original file line number Diff line number Diff line change @@ -45,8 +45,12 @@ void loop(void)
4545{
4646 distanceSensor.startRanging (); // Write configuration bytes to initiate measurement
4747
48+ while (!distanceSensor.checkForDataReady ()) {
49+ delay (1 );
50+ }
4851 int distance = distanceSensor.getDistance (); // Get the result of the measurement from the sensor
49-
52+ distanceSensor.clearInterrupt ();
53+
5054 distanceSensor.stopRanging ();
5155
5256 Serial.print (" Distance(mm): " );
Original file line number Diff line number Diff line change @@ -47,7 +47,11 @@ void loop(void)
4747{
4848 long startTime = millis ();
4949 distanceSensor.startRanging (); // Write configuration block of 135 bytes to setup a measurement
50+ while (!distanceSensor.checkForDataReady ()) {
51+ delay (1 );
52+ }
5053 int distance = distanceSensor.getDistance (); // Get the result of the measurement from the sensor
54+ distanceSensor.clearInterrupt ();
5155 distanceSensor.stopRanging ();
5256 long endTime = millis ();
5357
Original file line number Diff line number Diff line change @@ -32,17 +32,21 @@ void setup(void)
3232 Serial.println (" VL53L1X Qwiic Test" );
3333
3434 if (distanceSensor.begin () == 0 ) // Begin returns 0 on a good init
35- Serial.println (" Sensor online!" );
35+ Serial.println (" Sensor online!" );
3636
37- distanceSensor.setIntermeasurementPeriod (40 );
37+ // Intermeasurement period must be >= timing budget. Default = 100 ms.
38+ distanceSensor.setIntermeasurementPeriod (200 );
3839 Serial.println (distanceSensor.getIntermeasurementPeriod ());
40+ distanceSensor.startRanging (); // Start only once (and do never call stop)
3941}
4042
4143void loop (void )
4244{
43- distanceSensor.startRanging (); // Write configuration bytes to initiate measurement
45+ while (!distanceSensor.checkForDataReady ()) {
46+ delay (1 );
47+ }
4448 int distance = distanceSensor.getDistance (); // Get the result of the measurement from the sensor
45- distanceSensor.stopRanging ();
49+ distanceSensor.clearInterrupt ();
4650
4751 Serial.print (" Distance(mm): " );
4852 Serial.print (distance);
Original file line number Diff line number Diff line change @@ -83,7 +83,11 @@ void loop(void)
8383
8484 // Write configuration block of 135 bytes to setup a measurement
8585 distanceSensor.startRanging ();
86+ while (!distanceSensor.checkForDataReady ()) {
87+ delay (1 );
88+ }
8689 int distanceMM = distanceSensor.getDistance ();
90+ distanceSensor.clearInterrupt ();
8791 distanceSensor.stopRanging ();
8892
8993 lastReading = millis ();
You can’t perform that action at this time.
0 commit comments