2022-04-19 13:01:54 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include "pico/stdlib.h"
|
|
|
|
#include "hardware/i2c.h"
|
2022-05-17 12:24:50 +01:00
|
|
|
#include "vl53l5cx.hpp"
|
|
|
|
#include "src/vl53l5cx_firmware.h"
|
2022-04-19 13:01:54 +01:00
|
|
|
|
|
|
|
#include "common/pimoroni_i2c.hpp"
|
|
|
|
|
2022-04-19 17:24:06 +01:00
|
|
|
using namespace pimoroni;
|
2022-04-19 13:01:54 +01:00
|
|
|
|
2022-04-19 17:24:06 +01:00
|
|
|
I2C i2c(4, 5);
|
2022-05-17 12:24:50 +01:00
|
|
|
VL53L5CX vl53l5cx(&i2c, (uint8_t *)&vl53l5cx_firmware_bin);
|
2022-04-19 13:01:54 +01:00
|
|
|
|
|
|
|
int main() {
|
|
|
|
stdio_init_all();
|
|
|
|
|
2022-04-28 14:38:34 +01:00
|
|
|
bool result = vl53l5cx.init();
|
|
|
|
if(!result) {
|
|
|
|
printf("Error initializing...\n");
|
|
|
|
}
|
2022-04-19 17:24:06 +01:00
|
|
|
vl53l5cx.set_ranging_mode(VL53L5CX::RANGING_MODE_AUTONOMOUS);
|
|
|
|
vl53l5cx.set_resolution(VL53L5CX::RESOLUTION_4X4);
|
|
|
|
vl53l5cx.start_ranging();
|
2022-04-19 13:01:54 +01:00
|
|
|
|
|
|
|
while(true) {
|
2022-04-19 17:24:06 +01:00
|
|
|
if(vl53l5cx.data_ready()) {
|
|
|
|
VL53L5CX::ResultsData result;
|
|
|
|
if(vl53l5cx.get_data(&result)) {
|
|
|
|
printf("Distance: %dmm\n", result.distance_mm[0]);
|
2022-04-19 13:01:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
sleep_ms(20);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2022-04-19 17:24:06 +01:00
|
|
|
}
|