distance sensor is reset after powercycle

This commit is contained in:
Ollo 2023-03-22 21:06:14 +01:00
parent 9eb16637dc
commit bd2e4d3da0

View File

@ -10,6 +10,7 @@
#define SENSOR_PLANT 17 #define SENSOR_PLANT 17
VL53L0X tankSensor; VL53L0X tankSensor;
bool distanceReady = false;
void initializeTanksensor() { void initializeTanksensor() {
Wire.begin(SENSOR_TANK_SDA, SENSOR_TANK_SCL, 100000UL /* 100kHz */); Wire.begin(SENSOR_TANK_SDA, SENSOR_TANK_SCL, 100000UL /* 100kHz */);
@ -17,7 +18,6 @@ void initializeTanksensor() {
delay(100); delay(100);
tankSensor.setTimeout(500); tankSensor.setTimeout(500);
long start = millis(); long start = millis();
bool distanceReady = false;
while (start + 500 > millis()) while (start + 500 > millis())
{ {
if (tankSensor.init()) if (tankSensor.init())
@ -31,7 +31,7 @@ void initializeTanksensor() {
} }
} }
if (distanceReady) if ((distanceReady) && (!tankSensor.timeoutOccurred()))
{ {
Serial.println("Sensor init done"); Serial.println("Sensor init done");
tankSensor.setSignalRateLimit(0.1); tankSensor.setSignalRateLimit(0.1);
@ -61,7 +61,7 @@ void loop() {
delay(500); delay(500);
if (!tankSensor.timeoutOccurred()) if ((distanceReady) && (!tankSensor.timeoutOccurred()))
{ {
uint16_t distance = tankSensor.readRangeSingleMillimeters(); uint16_t distance = tankSensor.readRangeSingleMillimeters();
if (distance > 8000) { if (distance > 8000) {