From 8c840c599af1af665ced8c2fd390327f2580644e Mon Sep 17 00:00:00 2001 From: Ollo Date: Fri, 30 Oct 2020 22:51:32 +0100 Subject: [PATCH] Measure temperatur sensor multiple times --- esp32/src/main.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/esp32/src/main.cpp b/esp32/src/main.cpp index 08c7b3a..d7c828f 100644 --- a/esp32/src/main.cpp +++ b/esp32/src/main.cpp @@ -339,19 +339,18 @@ void readSensors() { /* Required to read the temperature once */ float temp[2] = {0, 0}; float* pFloat = temp; - // first read returns crap, ignore result and read twice - if (dallas.readAllTemperatures(pFloat, 2) > 0) { - Serial << "t1: " << String(temp[0]) << endl; - Serial << "t2: " << String(temp[1]) << endl; + for(int i=0; i < 10; i++) { + // first read returns crap, ignore result and read twice + if (dallas.readAllTemperatures(pFloat, 2) > 0) { + Serial << "t1: " << String(temp[0]) << endl; + Serial << "t2: " << String(temp[1]) << endl; + } + delay(200); + if (i <= 2) { + temp1.add(temp[0]); + temp2.add(temp[1]); + } } - delay(200); - if (dallas.readAllTemperatures(pFloat, 2) > 0) { - Serial << "t1: " << String(temp[0]) << endl; - Serial << "t2: " << String(temp[1]) << endl; - } - - temp1.add(temp[0]); - temp2.add(temp[1]); /* Use the Ultrasonic sensor to measure waterLevel */