Skip to content

Commit e80a0f4

Browse files
Merge pull request #34 from ArminJo/master
Improved examples
2 parents 4f5f83d + 2448a4e commit e80a0f4

File tree

5 files changed

+25
-5
lines changed

5 files changed

+25
-5
lines changed

Diff for: examples/Example1_ReadDistance/Example1_ReadDistance.ino

+4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ void setup(void)
4646
void 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): ");

Diff for: examples/Example2_SetDistanceMode/Example2_SetDistanceMode.ino

+5-1
Original file line numberDiff line numberDiff 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): ");

Diff for: examples/Example3_StatusAndRate/Example3_StatusAndRate.ino

+4
Original file line numberDiff line numberDiff 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

Diff for: examples/Example4_SetIntermeasurementPeriod/Example4_SetIntermeasurementPeriod.ino

+8-4
Original file line numberDiff line numberDiff 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

4143
void 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);

Diff for: examples/Example5_LCDDemo/Example5_LCDDemo.ino

+4
Original file line numberDiff line numberDiff 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();

0 commit comments

Comments
 (0)