From 1599185a257202bb2e6c5b63056d8beeb6b3ed6b Mon Sep 17 00:00:00 2001 From: igor Date: Wed, 5 Jul 2023 22:50:07 -0700 Subject: [PATCH] Update lcd on button click. --- aqi.ino | 94 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 54 insertions(+), 40 deletions(-) diff --git a/aqi.ino b/aqi.ino index 4d79b94..3c1f0ee 100644 --- a/aqi.ino +++ b/aqi.ino @@ -72,11 +72,11 @@ void setup() Wire.begin(); + sen44.begin(Wire); + uint16_t error; char errorMessage[256]; - sen44.begin(Wire); - error = sen44.deviceReset(); if (error) { Serial.print("Error trying to execute getSerialNumber(): "); @@ -95,17 +95,66 @@ void setup() // Clean Fan sen44.startFanCleaning(); + + // calibrate + lcd.setCursor(0, 0); + lcd.print(" calibrating..."); + + // allow 2 minute calibration + delay(120000); +} + +void update_lcd() +{ + lcd.clear(); + + if (isStandardValues) { + lcd.setCursor(0, 0); + lcd.print("t:"); + lcd.print(round(ambientTemperature)); + + lcd.setCursor(8, 0); + lcd.print("h:"); + lcd.print(round(ambientHumidity)); + + lcd.setCursor(0, 1); + lcd.print("f:"); + lcd.print(round(feelsLikeTemperature)); + + lcd.setCursor(8, 1); + lcd.print("v:"); + lcd.print(vocIndex, 0); + } else { + lcd.setCursor(0, 0); + lcd.print(" 1:"); + lcd.print(massConcentrationPm1p0); + + lcd.setCursor(8, 0); + lcd.print(" 2:"); + lcd.print(massConcentrationPm2p5); + + lcd.setCursor(0, 1); + lcd.print(" 4:"); + lcd.print(massConcentrationPm4p0); + + lcd.setCursor(8, 1); + lcd.print("10:"); + lcd.print(massConcentrationPm10p0); + } } void loop() { currentTime = millis(); - if (currentTime - buttonTime >= 500) { + // modes button + if (currentTime - buttonTime >= 100) { buttonTime = currentTime; - if (digitalRead(buttonPin) == LOW) + if (digitalRead(buttonPin) == LOW) { isStandardValues = !isStandardValues; + update_lcd(); + } } // sen44 @@ -135,41 +184,6 @@ void loop() // Display if (currentTime - lcdTime >= 2000) { lcdTime = currentTime; - - lcd.clear(); - - if (isStandardValues) { - lcd.setCursor(0, 0); - lcd.print("t:"); - lcd.print(round(ambientTemperature)); - - lcd.setCursor(8, 0); - lcd.print("h:"); - lcd.print(round(ambientHumidity)); - - lcd.setCursor(0, 1); - lcd.print("f:"); - lcd.print(round(feelsLikeTemperature)); - - lcd.setCursor(8, 1); - lcd.print("v:"); - lcd.print(vocIndex, 0); - } else { - lcd.setCursor(0, 0); - lcd.print(" 1:"); - lcd.print(massConcentrationPm1p0); - - lcd.setCursor(8, 0); - lcd.print(" 2:"); - lcd.print(massConcentrationPm2p5); - - lcd.setCursor(0, 1); - lcd.print(" 4:"); - lcd.print(massConcentrationPm4p0); - - lcd.setCursor(8, 1); - lcd.print("10:"); - lcd.print(massConcentrationPm10p0); - } + update_lcd(); } }