Skip to content

Commit f7411b9

Browse files
committed
Fix sketch and add complete sketch
1 parent 848b5b3 commit f7411b9

File tree

1 file changed

+44
-1
lines changed
  • content/hardware/05.nicla/boards/nicla-vision/tutorials/proximity

1 file changed

+44
-1
lines changed

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

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ Also the RGB LED needs to be set as an output to make it light up.
6868
```cpp
6969
void setup(){
7070
Serial.begin(115200);
71-
71+
Wire1.begin();
72+
7273
pinMode(LEDB,OUTPUT);
7374
digitalWrite(LEDB, blinkState);
7475
@@ -101,6 +102,48 @@ The sketch is going to get the reading on every loop, store it and then the stat
101102
}
102103
```
103104
105+
### Complete Sketch
106+
107+
```cpp
108+
#include <Wire.h>
109+
#include "VL53L1X.h"
110+
VL53L1X proximity(Wire1);
111+
112+
bool blinkState = false;
113+
int reading = 0;
114+
int timeStart = 0;
115+
int blinkTime = 2000;
116+
117+
void setup(){
118+
Serial.begin(115200);
119+
Wire1.begin();
120+
121+
pinMode(LEDB,OUTPUT);
122+
digitalWrite(LEDB, blinkState);
123+
124+
if (!proximity.init()){
125+
Serial.println("Failed to detect and initialize sensor!");
126+
while (1);
127+
}
128+
129+
proximity.setDistanceMode(VL53L1X::Long);
130+
proximity.setMeasurementTimingBudget(10000);
131+
proximity.startContinuous(10);
132+
}
133+
134+
void loop(){
135+
reading = proximity.read();
136+
Serial.println(reading);
137+
138+
if (millis() - timeStart >= reading){
139+
digitalWrite(LEDB, blinkState);
140+
timeStart = millis();
141+
142+
blinkState = !blinkState;
143+
}
144+
}
145+
```
146+
104147
## API
105148
| Command | Details | type |
106149
| :----------------------------------- | :----------------------------------------------------------: | :---------------- |

0 commit comments

Comments
 (0)