display function now executes every loop instead of 5 seconds
This commit is contained in:
@@ -31,16 +31,16 @@ WebSocketsClient webSocket;
|
|||||||
// define variables
|
// define variables
|
||||||
uint16_t TVOC_base, eCO2_base;
|
uint16_t TVOC_base, eCO2_base;
|
||||||
uint16_t counter = 0;
|
uint16_t counter = 0;
|
||||||
float temperature = 0;
|
|
||||||
float humidity = 0;
|
|
||||||
uint16_t eCO2 = 0;
|
uint16_t eCO2 = 0;
|
||||||
uint16_t TVOC = 0;
|
uint16_t TVOC = 0;
|
||||||
bool noise = false;
|
|
||||||
unsigned long currentCounter;
|
|
||||||
unsigned long lastCounter;
|
|
||||||
uint16_t interval = 5000;
|
uint16_t interval = 5000;
|
||||||
|
float temperature = 0;
|
||||||
|
float humidity = 0;
|
||||||
|
unsigned long currentMillis;
|
||||||
|
unsigned long lastMillis;
|
||||||
bool errorSGP30 = false;
|
bool errorSGP30 = false;
|
||||||
bool errorDHT11 = false;
|
bool errorDHT11 = false;
|
||||||
|
bool noise = false;
|
||||||
|
|
||||||
// hexdump function for websockets binary handler
|
// hexdump function for websockets binary handler
|
||||||
void hexdump(const void *mem, uint32_t len, uint8_t cols = 16) {
|
void hexdump(const void *mem, uint32_t len, uint8_t cols = 16) {
|
||||||
@@ -119,8 +119,8 @@ void resetValues() {
|
|||||||
eCO2 = 0;
|
eCO2 = 0;
|
||||||
TVOC = 0;
|
TVOC = 0;
|
||||||
noise = false;
|
noise = false;
|
||||||
lastCounter = 0;
|
lastMillis = 0;
|
||||||
currentCounter = 0;
|
currentMillis = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// function to check for errors in sensors
|
// function to check for errors in sensors
|
||||||
@@ -159,8 +159,7 @@ void update(){
|
|||||||
temperature = float(dht.readTemperature());
|
temperature = float(dht.readTemperature());
|
||||||
humidity = float(dht.readHumidity());
|
humidity = float(dht.readHumidity());
|
||||||
|
|
||||||
// display sensordata on oled screen
|
|
||||||
displayData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// function to display data on oled screen
|
// function to display data on oled screen
|
||||||
@@ -203,12 +202,18 @@ void setup() {
|
|||||||
|
|
||||||
// loop function
|
// loop function
|
||||||
void loop() {
|
void loop() {
|
||||||
|
// loop the websocket connection so it stays alive
|
||||||
webSocket.loop();
|
webSocket.loop();
|
||||||
|
|
||||||
if (currentCounter - lastCounter >= interval){
|
// display sensordata on oled screen
|
||||||
lastCounter = millis();
|
displayData();
|
||||||
|
|
||||||
|
// update when interval is met
|
||||||
|
if (currentMillis - lastMillis >= interval){
|
||||||
|
lastMillis = millis();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
currentCounter = millis();
|
// update the counter
|
||||||
|
currentMillis = millis();
|
||||||
}
|
}
|
Reference in New Issue
Block a user