-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
48 lines (30 loc) · 754 Bytes
/
Copy pathmain.cpp
File metadata and controls
48 lines (30 loc) · 754 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <Arduino.h>
#include <Wire.h>
#include <VL53L0X.h>
VL53L0X sensor;
void setup() {
Serial.begin(115200);
// SDA = 21
// SCL = 22
Wire.begin(21, 22);
Serial.println("Iniciando VL53L0X...");
sensor.setTimeout(500);
if (!sensor.init()) {
Serial.println("Falha ao detectar VL53L0X!");
while (1);
}
Serial.println("Sensor encontrado!");
// Inicia modo continuo
sensor.startContinuous();
}
void loop() {
int distancia = sensor.readRangeContinuousMillimeters();
if (sensor.timeoutOccurred()) {
Serial.println("Timeout!");
} else {
Serial.print("Distancia: ");
Serial.print(distancia);
Serial.println(" mm");
}
delay(100);
}