the buzzer has a delay, so let's update the LCD before making noise.
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);
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);
}