File tree Expand file tree Collapse file tree 1 file changed +44
-1
lines changed
content/hardware/05.nicla/boards/nicla-vision/tutorials/proximity Expand file tree Collapse file tree 1 file changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -68,7 +68,8 @@ Also the RGB LED needs to be set as an output to make it light up.
68
68
```cpp
69
69
void setup(){
70
70
Serial.begin(115200);
71
-
71
+ Wire1.begin();
72
+
72
73
pinMode(LEDB,OUTPUT);
73
74
digitalWrite(LEDB, blinkState);
74
75
@@ -101,6 +102,48 @@ The sketch is going to get the reading on every loop, store it and then the stat
101
102
}
102
103
```
103
104
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
+
104
147
## API
105
148
| Command | Details | type |
106
149
| :----------------------------------- | :----------------------------------------------------------: | :---------------- |
You can’t perform that action at this time.
0 commit comments