move LCD output before buzzer
authorgregor herrmann <gregor@toastfreeware.priv.at>
Sun, 1 Nov 2020 03:32:05 +0000 (04:32 +0100)
committergregor herrmann <gregor@toastfreeware.priv.at>
Sun, 1 Nov 2020 03:32:05 +0000 (04:32 +0100)
the buzzer has a delay, so let's update the LCD before making noise.

airingbutler.ino

index 92461a63cd8f94d5ba5de40d0532ac569c373f7c..ebdc5ee67a80f95141a766b2e346cef797b1e4d6 100644 (file)
@@ -85,20 +85,12 @@ void loop()
        Serial.print(",");
        Serial.println(temp);
 
+       // LEDs
        digitalWrite(led_red_pin, co2 >= co2_alarm_thr);
        digitalWrite(led_yellow_pin, co2 >= co2_warning_thr && co2 < co2_alarm_thr);
        digitalWrite(led_green_pin, co2 < co2_warning_thr);
 
-       if (co2 >= co2_alarm_thr && lastppm < co2_alarm_thr && time - lastwarntime > cooldowntime) {
-               buzz(100, 3);
-               lastwarntime = time;
-       }
-
-       if (co2 >= co2_warning_thr && lastppm < co2_warning_thr && time - lastwarntime > cooldowntime) {
-               buzz(500, 1);
-               lastwarntime = time;
-       }
-
+       // LCD
        lcd.setCursor(0, 0);
        lcd.print("CO2: ");
        lcd.print(co2);
@@ -111,6 +103,16 @@ void loop()
        lcd.print(temp);
        lcd.print(" C +/-  ");
 
+       // buzzer
+       if (co2 >= co2_alarm_thr && lastppm < co2_alarm_thr && time - lastwarntime > cooldowntime) {
+               buzz(100, 3);
+               lastwarntime = time;
+       }
+       if (co2 >= co2_warning_thr && lastppm < co2_warning_thr && time - lastwarntime > cooldowntime) {
+               buzz(500, 1);
+               lastwarntime = time;
+       }
+
        lastppm = co2;
        delay(5000);
 }