forked from github/ebk_co2ampel
experimental feature: calibration when rebootet before 10s uptime
This commit is contained in:
parent
822429e456
commit
9830ad9984
1 changed files with 39 additions and 3 deletions
|
@ -3,6 +3,7 @@
|
||||||
#include "SSD1306Wire.h"
|
#include "SSD1306Wire.h"
|
||||||
#include <Adafruit_NeoPixel.h>
|
#include <Adafruit_NeoPixel.h>
|
||||||
#include "fonts-custom.h"
|
#include "fonts-custom.h"
|
||||||
|
#include <Preferences.h>
|
||||||
|
|
||||||
// Maximum CO² levels for green and yellow, everything above is considered red.
|
// Maximum CO² levels for green and yellow, everything above is considered red.
|
||||||
#define GREEN_CO2 800
|
#define GREEN_CO2 800
|
||||||
|
@ -25,6 +26,7 @@
|
||||||
// number of LEDs connected
|
// number of LEDs connected
|
||||||
#define NUMPIXELS 12
|
#define NUMPIXELS 12
|
||||||
|
|
||||||
|
Preferences preferences;
|
||||||
|
|
||||||
MHZ19 myMHZ19;
|
MHZ19 myMHZ19;
|
||||||
HardwareSerial mySerial(1);
|
HardwareSerial mySerial(1);
|
||||||
|
@ -34,21 +36,47 @@ Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, LED_PIN, NEO_RGB + NEO_K
|
||||||
unsigned long getDataTimer = 0;
|
unsigned long getDataTimer = 0;
|
||||||
int lastvals[120];
|
int lastvals[120];
|
||||||
int dheight;
|
int dheight;
|
||||||
String ampelversion = "smash20201117-01";
|
String ampelversion = "0.1";
|
||||||
|
int safezone = 1;
|
||||||
|
int tocalibrateornot;
|
||||||
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
Serial.println("boot...");
|
Serial.println("boot...");
|
||||||
|
preferences.begin("co2", false);
|
||||||
|
tocalibrateornot = preferences.getUInt("cal",13); // wir lesen unser flag ein, 23 = reboot vor safezone, wir wollen kalibrieren, 42 = reboot nach safezone, wir tun nichts
|
||||||
|
preferences.putUInt("cal", 23); // wir sind gerade gestartet
|
||||||
Serial.println(ampelversion);
|
Serial.println(ampelversion);
|
||||||
mySerial.begin(9600, SERIAL_8N1, RX_PIN, TX_PIN);
|
mySerial.begin(9600, SERIAL_8N1, RX_PIN, TX_PIN);
|
||||||
myMHZ19.begin(mySerial);
|
myMHZ19.begin(mySerial);
|
||||||
pixels.clear();
|
pixels.clear();
|
||||||
display.init();
|
display.init();
|
||||||
display.setContrast(255);
|
display.setContrast(255);
|
||||||
delay(1000);
|
delay(500);
|
||||||
display.clear();
|
display.clear();
|
||||||
display.flipScreenVertically();
|
display.flipScreenVertically();
|
||||||
|
display.setTextAlignment(TEXT_ALIGN_CENTER);
|
||||||
|
display.drawString(64 ,0 , String(ampelversion));
|
||||||
|
display.display();
|
||||||
dheight = display.getHeight();
|
dheight = display.getHeight();
|
||||||
myMHZ19.autoCalibration();
|
// myMHZ19.autoCalibration();
|
||||||
|
Serial.print("read EEPROM value: ");
|
||||||
|
Serial.println(tocalibrateornot);
|
||||||
|
if (tocalibrateornot == 23){
|
||||||
|
Serial.println("brace yourself, calibration starting! things either be better or all fucked up beyond this point...");
|
||||||
|
display.drawString(64, 20, "Calibration!");
|
||||||
|
display.display();
|
||||||
|
myMHZ19.setRange(2000);
|
||||||
|
myMHZ19.calibrateZero();
|
||||||
|
myMHZ19.setSpan(2000);
|
||||||
|
myMHZ19.autoCalibration(false);
|
||||||
|
Serial.println("calibration done");
|
||||||
|
Serial.print("ABC Status: "); myMHZ19.getABC() ? Serial.println("ON") : Serial.println("OFF");
|
||||||
|
}
|
||||||
|
else if (tocalibrateornot ==42){
|
||||||
|
Serial.println("fake news, nobody has the intention to do calibration....");
|
||||||
|
}
|
||||||
// Fill array of last measurements with -1
|
// Fill array of last measurements with -1
|
||||||
for (int x = 0; x <= 119; x = x + 1) {
|
for (int x = 0; x <= 119; x = x + 1) {
|
||||||
lastvals[x] = -1;
|
lastvals[x] = -1;
|
||||||
|
@ -89,6 +117,14 @@ void set_led_color(int co2) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
if (safezone == 1){
|
||||||
|
if (millis() == 10000) {
|
||||||
|
Serial.println(" safe zone, sensor stayed up longer than 10s");
|
||||||
|
preferences.putUInt("cal", 42); // wir haben die safe zone erreicht, beim naechsten boot nicht kalibrieren!
|
||||||
|
safezone = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (millis() - getDataTimer >= INTERVAL) {
|
if (millis() - getDataTimer >= INTERVAL) {
|
||||||
// Get new CO² value.
|
// Get new CO² value.
|
||||||
int CO2 = myMHZ19.getCO2();
|
int CO2 = myMHZ19.getCO2();
|
||||||
|
|
Loading…
Reference in a new issue