Skip to content

Commit 33d2151

Browse files
committed
Fix sketch
1 parent 77e25d1 commit 33d2151

File tree

1 file changed

+16
-12
lines changed
  • content/hardware/05.nicla/boards/nicla-vision/tutorials/proximity

1 file changed

+16
-12
lines changed

content/hardware/05.nicla/boards/nicla-vision/tutorials/proximity/content.md

+16-12
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,14 @@ To make sure that the sketch works properly, the latest versions of the **Arduin
4848
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.
4949

5050
```cpp
51-
#include <Wire.h>
5251
#include "VL53L1X.h"
53-
VL53L1X proximity(Wire1);
52+
VL53L1X proximity;
5453

5554
bool blinkState = false;
5655
int reading = 0;
5756
int timeStart = 0;
5857
int blinkTime = 2000;
5958
```
60-
***Make sure you set `Wire1` inside the VL53L1X constructor's parameter, it won't work if you don't add this setting***
6159

6260
### Initialize the Proximity Sensor and the LED
6361

@@ -69,6 +67,8 @@ Inside the setup you need to initialize and configure the proximity sensor. Also
6967
void setup(){
7068
Serial.begin(115200);
7169
Wire1.begin();
70+
Wire1.setClock(400000); // use 400 kHz I2C
71+
proximity.setBus(&Wire1);
7272

7373
pinMode(LEDB,OUTPUT);
7474
digitalWrite(LEDB, blinkState);
@@ -84,6 +84,8 @@ Inside the setup you need to initialize and configure the proximity sensor. Also
8484
}
8585
```
8686
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+
8789
### Control the Speed of the Blink
8890
8991
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
105107
### Complete Sketch
106108

107109
```cpp
108-
#include <Wire.h>
109110
#include "VL53L1X.h"
110-
VL53L1X proximity(Wire1);
111+
VL53L1X proximity;
111112

112113
bool blinkState = false;
113114
int reading = 0;
114115
int timeStart = 0;
115116
int blinkTime = 2000;
116117

117-
void setup(){
118+
void setup() {
118119
Serial.begin(115200);
119120
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);
122126
digitalWrite(LEDB, blinkState);
123-
124-
if (!proximity.init()){
127+
128+
if (!proximity.init()) {
125129
Serial.println("Failed to detect and initialize sensor!");
126130
while (1);
127131
}
@@ -131,11 +135,11 @@ void setup(){
131135
proximity.startContinuous(10);
132136
}
133137

134-
void loop(){
138+
void loop() {
135139
reading = proximity.read();
136140
Serial.println(reading);
137141

138-
if (millis() - timeStart >= reading){
142+
if (millis() - timeStart >= reading) {
139143
digitalWrite(LEDB, blinkState);
140144
timeStart = millis();
141145

0 commit comments

Comments
 (0)