File tree 5 files changed +25
-5
lines changed
Example4_SetIntermeasurementPeriod
5 files changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,11 @@ void setup(void)
46
46
void loop (void )
47
47
{
48
48
distanceSensor.startRanging (); // Write configuration bytes to initiate measurement
49
+ while (!distanceSensor.checkForDataReady ()) {
50
+ delay (1 );
51
+ }
49
52
int distance = distanceSensor.getDistance (); // Get the result of the measurement from the sensor
53
+ distanceSensor.clearInterrupt ();
50
54
distanceSensor.stopRanging ();
51
55
52
56
Serial.print (" Distance(mm): " );
Original file line number Diff line number Diff line change @@ -45,8 +45,12 @@ void loop(void)
45
45
{
46
46
distanceSensor.startRanging (); // Write configuration bytes to initiate measurement
47
47
48
+ while (!distanceSensor.checkForDataReady ()) {
49
+ delay (1 );
50
+ }
48
51
int distance = distanceSensor.getDistance (); // Get the result of the measurement from the sensor
49
-
52
+ distanceSensor.clearInterrupt ();
53
+
50
54
distanceSensor.stopRanging ();
51
55
52
56
Serial.print (" Distance(mm): " );
Original file line number Diff line number Diff line change @@ -47,7 +47,11 @@ void loop(void)
47
47
{
48
48
long startTime = millis ();
49
49
distanceSensor.startRanging (); // Write configuration block of 135 bytes to setup a measurement
50
+ while (!distanceSensor.checkForDataReady ()) {
51
+ delay (1 );
52
+ }
50
53
int distance = distanceSensor.getDistance (); // Get the result of the measurement from the sensor
54
+ distanceSensor.clearInterrupt ();
51
55
distanceSensor.stopRanging ();
52
56
long endTime = millis ();
53
57
Original file line number Diff line number Diff line change @@ -32,17 +32,21 @@ void setup(void)
32
32
Serial.println (" VL53L1X Qwiic Test" );
33
33
34
34
if (distanceSensor.begin () == 0 ) // Begin returns 0 on a good init
35
- Serial.println (" Sensor online!" );
35
+ Serial.println (" Sensor online!" );
36
36
37
- distanceSensor.setIntermeasurementPeriod (40 );
37
+ // Intermeasurement period must be >= timing budget. Default = 100 ms.
38
+ distanceSensor.setIntermeasurementPeriod (200 );
38
39
Serial.println (distanceSensor.getIntermeasurementPeriod ());
40
+ distanceSensor.startRanging (); // Start only once (and do never call stop)
39
41
}
40
42
41
43
void loop (void )
42
44
{
43
- distanceSensor.startRanging (); // Write configuration bytes to initiate measurement
45
+ while (!distanceSensor.checkForDataReady ()) {
46
+ delay (1 );
47
+ }
44
48
int distance = distanceSensor.getDistance (); // Get the result of the measurement from the sensor
45
- distanceSensor.stopRanging ();
49
+ distanceSensor.clearInterrupt ();
46
50
47
51
Serial.print (" Distance(mm): " );
48
52
Serial.print (distance);
Original file line number Diff line number Diff line change @@ -83,7 +83,11 @@ void loop(void)
83
83
84
84
// Write configuration block of 135 bytes to setup a measurement
85
85
distanceSensor.startRanging ();
86
+ while (!distanceSensor.checkForDataReady ()) {
87
+ delay (1 );
88
+ }
86
89
int distanceMM = distanceSensor.getDistance ();
90
+ distanceSensor.clearInterrupt ();
87
91
distanceSensor.stopRanging ();
88
92
89
93
lastReading = millis ();
You can’t perform that action at this time.
0 commit comments