-
Notifications
You must be signed in to change notification settings - Fork 0
/
indoor-atmosphere.ino
75 lines (51 loc) · 1.34 KB
/
indoor-atmosphere.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <GyverButton.h>
#include <GyverBME280.h>
#include <SoftwareSerial.h>
#include <microLiquidCrystal_I2C.h>
//Screen
LiquidCrystal_I2C lcd(0x27, 16, 2);
bool backlight_on = false;
//BME
GyverBME280 bme;
//MHZ-19 B
SoftwareSerial swSerial(A0, A1); // RX, TX
//button
GButton but(3);
unsigned int ppm = 0, temp = 0, humid = 0, pres = 0, lastCheck = 0;
unsigned int lastValues[4] = {0, 0, 0, 0};
void setup() {
//Screens
connectLCD();
//BME
connectBME();
//MHZ-19B
//connectMhz19b(0);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
but.tick();
if (but.isPress()) {
toggleBacklight();
}
if ((millis() / 1000) - lastCheck > 15 || lastCheck == 0) {
lastCheck = millis() / 1000;
blinkBuiltin();
bme.oneMeasurement(); // BME goes to sleep after measuring when in Forced mode
temp = round(bme.readTemperature());
humid = round(bme.readHumidity());
pres = round(pressureToMmHg(bme.readPressure()));
//ppm = measureCO2();
if (temp != lastValues[0] || humid != lastValues[1] || pres != lastValues[2] || ppm != lastValues[3]) {
lastValues[0] = temp;
lastValues[1] = humid;
lastValues[2] = pres;
lastValues[3] = ppm;
printValues(temp, humid, pres, ppm);
}
}
}
void blinkBuiltin() {
digitalWrite(LED_BUILTIN, HIGH);
delay(100);
digitalWrite(LED_BUILTIN, LOW);
}