#include <VL53L0X.h> int x = 0; VL53L0X sensor; void setup() { Serial.begin(9600); Wire.begin(); pinMode(A3, OUTPUT); digitalWrite(A3, 1); sensor.setTimeout(500); if (!sensor.init()) { while (1) {}} #if defined LONG_RANGE sensor.setSignalRateLimit(0.1); sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange, 18); sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange, 14); #endif #if defined HIGH_SPEED sensor.setMeasurementTimingBudget(20000); #elif defined HIGH_ACCURACY sensor.setMeasurementTimingBudget(200000); #endif } void loop() { x = sensor.readRangeSingleMillimeters(); Serial.println(x); if (x < 50) { pinMode(13, OUTPUT); digitalWrite(13, 1); } else { pinMode(13, OUTPUT); digitalWrite(13, 0); } }
Открыть пример: Online ArduBlock
Видеоурок: