publish any change in temperature, but display only if difference is more than 0.2

This commit is contained in:
Nicu Hodos 2024-01-02 22:02:46 +01:00
parent 23de23a2e0
commit bdefbf23bc

View File

@ -29,12 +29,15 @@ Task tLed(TASK_IMMEDIATE, TASK_ONCE, []() {
}, &ts);
Task tReadBmp(TASK_MINUTE, TASK_FOREVER, []() {
static float lastTemp = 0;
float temp = Bmp::data.temp;
Bmp::data.readAll();
if (abs(lastTemp - Bmp::data.temp) <= 0.2) return;
lastTemp = Bmp::data.temp;
Display::displayTemp(Bmp::data.temp);
if (temp == Bmp::data.temp) return;
Mqtt::publishBmp280();
}, &ts, true);
if (abs(lastTemp - Bmp::data.temp) > 0.2) {
lastTemp = Bmp::data.temp;
Display::displayTemp(Bmp::data.temp);
}
}, &ts);
void setup() {
@ -55,6 +58,8 @@ void setup() {
pinMode(BUTTON, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(BUTTON), onButtonPressed, FALLING);
attachInterrupt(digitalPinToInterrupt(LED_BUILTIN), onLed, CHANGE);
tReadBmp.enable();
}
void loop() {