Display also humidity and pressure
Display update triggered by value change, not interval
This commit is contained in:
51
bme280.ino
51
bme280.ino
@@ -1,23 +1,50 @@
|
||||
#include "Seeed_BME280.h"
|
||||
|
||||
enum {
|
||||
LOWER = 0,
|
||||
HIGHER
|
||||
};
|
||||
|
||||
BME280 sensor;
|
||||
float highTemp = 0.0, lowTemp = 0.0;
|
||||
const float blindZone = 0.03;
|
||||
float bounds[2][SENSORS] = {};
|
||||
const float hysteresisWidth[SENSORS] = {0.03, 0.5, 0.5};
|
||||
|
||||
void initBME280() {
|
||||
sensor.init();
|
||||
}
|
||||
|
||||
void readTemperature() {
|
||||
float newTemperature = sensor.getTemperature();
|
||||
void readSensors() {
|
||||
float newValue;
|
||||
|
||||
if (newTemperature > highTemp) {
|
||||
temperature = newTemperature;
|
||||
highTemp = newTemperature;
|
||||
lowTemp = highTemp - blindZone;
|
||||
} else if (newTemperature < lowTemp) {
|
||||
temperature = newTemperature;
|
||||
lowTemp = newTemperature;
|
||||
highTemp = lowTemp + blindZone;
|
||||
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;
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user