Files
metronom/bme280.ino
cryptogopher c2af98d588 Display also humidity and pressure
Display update triggered by value change, not interval
2026-02-12 00:10:45 +01:00

51 lines
1.1 KiB
C++

#include "Seeed_BME280.h"
enum {
LOWER = 0,
HIGHER
};
BME280 sensor;
float bounds[2][SENSORS] = {};
const float hysteresisWidth[SENSORS] = {0.03, 0.5, 0.5};
void initBME280() {
sensor.init();
}
void readSensors() {
float newValue;
for (uint i = 0; i < SENSORS; i++) {
switch (i) {
case TEMPERATURE:
newValue = sensor.getTemperature();
break;
case HUMIDITY:
newValue = sensor.getHumidity();
break;
case PRESSURE:
newValue = sensor.getPressure();
break;
}
if (newValue > bounds[HIGHER][i]) {
sensorValue[i] = newValue;
bounds[HIGHER][i] = newValue;
bounds[LOWER][i] = bounds[HIGHER][i] - hysteresisWidth[i];
if ((countdown <= 0) && (displaySensor == i)) {
displayNeedsUpdate = true;
}
} else if (newValue < bounds[LOWER][i]) {
sensorValue[i] = newValue;
bounds[LOWER][i] = newValue;
bounds[HIGHER][i] = bounds[LOWER][i] + hysteresisWidth[i];
if ((countdown <= 0) && (displaySensor == i)) {
displayNeedsUpdate = true;
}
};
};
}