51 lines
1.1 KiB
C++
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;
|
|
}
|
|
};
|
|
};
|
|
}
|