only read temperature multiple times, if it differs significantly to last measurement

This commit is contained in:
c3ma 2020-11-11 21:09:38 +01:00
parent 04bfaf4d94
commit ade0a8b812

View File

@ -382,7 +382,8 @@ bool readSensors()
delay(200);
/* Required to read the temperature once */
for (int i = 0; i < 5; i++)
int readAgain = 5;
while (readAgain > 0)
{
int sensors = dallas.readAllTemperatures(pFloat, 2);
if (sensors > 0)
@ -395,9 +396,6 @@ bool readSensors()
Serial << "t2: " << String(temp[1]) << endl;
temp2.add(temp[1]);
}
delay(50);
}
if ((temp1.getAverage() - rtcLastTemp1 > TEMPERATURE_DELTA_TRIGGER_IN_C) ||
(rtcLastTemp1 - temp1.getAverage() > TEMPERATURE_DELTA_TRIGGER_IN_C)) {
leaveMode1 = true;
@ -406,6 +404,15 @@ bool readSensors()
(rtcLastTemp2 - temp2.getAverage() > TEMPERATURE_DELTA_TRIGGER_IN_C)) {
leaveMode1 = true;
}
if(!leaveMode1){
readAgain = 0;
}
readAgain--;
delay(50);
}
rtcLastTemp1 = temp1.getAverage();
rtcLastTemp2 = temp2.getAverage();