датчик VL53L0X срабатывание реле по уставкам
- Войдите на сайт для отправки комментариев
Чт, 31/01/2019 - 21:06
Всем привет.
ищу помощи.
есть датчик VL53L0X и ардуино нано. надо чтобы выход D12 активировался по расстоянию от 0 до 100 см.
поправил скетч ардуиновский, но не работает.
где косяк? кто поправит правильно?
/* This example shows how to get single-shot range
measurements from the VL53L0X. The sensor can optionally be
configured with different ranging profiles, as described in
the VL53L0X API user manual, to get better performance for
a certain application. This code is based on the four
"SingleRanging" examples in the VL53L0X API.
The range readings are in units of mm. */
#include <Wire.h>
#include <VL53L0X.h>
VL53L0X sensor;
const int alarmPin = 12;
long duration, cm;
// Uncomment this line to use long range mode. This
// increases the sensitivity of the sensor and extends its
// potential range, but increases the likelihood of getting
// an inaccurate reading because of reflections from objects
// other than the intended target. It works best in dark
// conditions.
#define LONG_RANGE
// Uncomment ONE of these two lines to get
// - higher speed at the cost of lower accuracy OR
// - higher accuracy at the cost of lower speed
//#define HIGH_SPEED
#define HIGH_ACCURACY
void setup()
{
Serial.begin(9600);
Wire.begin();
sensor.init();
sensor.setTimeout(500);
pinMode(alarmPin, OUTPUT);
#if defined LONG_RANGE
// lower the return signal rate limit (default is 0.25 MCPS)
sensor.setSignalRateLimit(0.1);
// increase laser pulse periods (defaults are 14 and 10 PCLKs)
sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange, 18);
sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange, 14);
#endif
#if defined HIGH_SPEED
// reduce timing budget to 20 ms (default is about 33 ms)
sensor.setMeasurementTimingBudget(20000);
#elif defined HIGH_ACCURACY
// increase timing budget to 200 ms
sensor.setMeasurementTimingBudget(200000);
#endif
}
void loop()
{
Serial.print(sensor.readRangeSingleMillimeters());
if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
Serial.println();
duration = sensor.init();
cm = duration;
if(cm > 0 && cm < 100){digitalWrite(alarmPin,LOW );
}else{digitalWrite(alarmPin, HIGH);}
}
А, простите, где Вы взяли этот "скетч ардуиновский"? А, вижу - "сам поправил".
где косяк?
Косяк в подходе к делу. Вы "правите" методом тыка, не понимая ни единой буквы.
В строках №№ 68-69 написан чистый, рафинированый бред, уж простите мой французский. Начнём с того, что init возвращает тип bool, ну и так далее. Вы бы хоть свою cm в монитор порта вывели и посмотрели бы на неё!
кто поправит правильно?
Запостите в профильном разделе. Там найдётся кто-нибудь.
спасибо за подсказку.!