-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVL53L1.ino
61 lines (46 loc) · 1.33 KB
/
VL53L1.ino
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
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "Adafruit_VL53L1X.h"
// tentar usar o sparkfun
#define IRQ_PIN 25
#define XSHUT_PIN 26
//Adafruit_VL53L1X vl53 = Adafruit_VL53L1X(XSHUT_PIN, IRQ_PIN);
Adafruit_VL53L1X vl53 = Adafruit_VL53L1X();
uint8_t vl53_module_num;
bool GotData = false;
uint16_t ErrorStatus;
bool vl53l1_boot ( uint8_t mybootnum ) {
vl53_module_num = mybootnum;
tcaselect(TCA_VL3);
if (!vl53.begin()) return false;
vl53.setIntPolarity(true);
return true;
}
void vl53l1_read () {
if (!ModuleData[vl53_module_num].Register.ModuleDetected) return;
tcaselect(TCA_VL3);
if (! vl53.startRanging()) {
Serial.print(F("Couldn't start ranging: "));
Serial.println(vl53.vl_status);
}
vl53.setTimingBudget(50);
int16_t distance;
if (vl53.dataReady()) {
distance = vl53.distance();
if (distance == -1) {
ErrorStatus = vl53.vl_status;
GotData = false;
return;
}
GotData = true;
SensorData.vl53l1Data.Distance = distance;
vl53.clearInterrupt();
vl53.stopRanging();
}
}
void vl53l1_print () {
if (!ModuleData[vl53_module_num].Register.ModuleDetected) return;
if (GotData) {
printf( "VL5: Distance [%4u] mm\n", SensorData.vl53l1Data.Distance );
} else {
printf( "VL5: out of range %u\n", ErrorStatus);
}
}