You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/hardware/05.nicla/boards/nicla-vision/tutorials/proximity/content.md
+16-12
Original file line number
Diff line number
Diff line change
@@ -48,16 +48,14 @@ To make sure that the sketch works properly, the latest versions of the **Arduin
48
48
First of all declare the sensor's class so you can access it later on in your sketch. We use variables to control the time elements in the sketch. This will make sure that the readings stay accurate over time.
49
49
50
50
```cpp
51
-
#include<Wire.h>
52
51
#include"VL53L1X.h"
53
-
VL53L1X proximity(Wire1);
52
+
VL53L1X proximity;
54
53
55
54
bool blinkState = false;
56
55
int reading = 0;
57
56
int timeStart = 0;
58
57
int blinkTime = 2000;
59
58
```
60
-
***Make sure you set `Wire1` inside the VL53L1X constructor's parameter, it won't work if you don't add this setting***
61
59
62
60
### Initialize the Proximity Sensor and the LED
63
61
@@ -69,6 +67,8 @@ Inside the setup you need to initialize and configure the proximity sensor. Also
69
67
voidsetup(){
70
68
Serial.begin(115200);
71
69
Wire1.begin();
70
+
Wire1.setClock(400000); // use 400 kHz I2C
71
+
proximity.setBus(&Wire1);
72
72
73
73
pinMode(LEDB,OUTPUT);
74
74
digitalWrite(LEDB, blinkState);
@@ -84,6 +84,8 @@ Inside the setup you need to initialize and configure the proximity sensor. Also
84
84
}
85
85
```
86
86
87
+
***Make sure you intialize `Wire1`, set the clock speed to 400kHz and set the bus pointer to `Wire1`, it won't work if you don't add these setting***
88
+
87
89
### Control the Speed of the Blink
88
90
89
91
The sketch is going to get the reading on every loop, store it and then the state of the LED will change, until the time is up and another proximity reading is taken.
@@ -105,23 +107,25 @@ The sketch is going to get the reading on every loop, store it and then the stat
105
107
### Complete Sketch
106
108
107
109
```cpp
108
-
#include <Wire.h>
109
110
#include"VL53L1X.h"
110
-
VL53L1X proximity(Wire1);
111
+
VL53L1X proximity;
111
112
112
113
bool blinkState = false;
113
114
int reading = 0;
114
115
int timeStart = 0;
115
116
int blinkTime = 2000;
116
117
117
-
void setup(){
118
+
voidsetup(){
118
119
Serial.begin(115200);
119
120
Wire1.begin();
120
-
121
-
pinMode(LEDB,OUTPUT);
121
+
Wire1.setClock(400000); // use 400 kHz I2C
122
+
proximity.setBus(&Wire1);
123
+
124
+
125
+
pinMode(LEDB, OUTPUT);
122
126
digitalWrite(LEDB, blinkState);
123
-
124
-
if (!proximity.init()){
127
+
128
+
if (!proximity.init()){
125
129
Serial.println("Failed to detect and initialize sensor!");
0 commit comments