From 66f287bf4f7cae9ad45b2ceba74f3f28d6104f80 Mon Sep 17 00:00:00 2001 From: gregor herrmann Date: Sun, 1 Nov 2020 02:51:58 +0100 Subject: [PATCH] add a "cooldown time" MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit don't warn more often than once per time period (currently one minute), to avoid constant beeping when the co₂ value flaps around the threshold. --- airingbutler.ino | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/airingbutler.ino b/airingbutler.ino index b4579e6..92461a6 100644 --- a/airingbutler.ino +++ b/airingbutler.ino @@ -14,12 +14,14 @@ const int buzzer_pin = 13; const int co2_warning_thr = 1000; const int co2_alarm_thr = 1500; -const unsigned long warmuptime = 60000; // 1 min. +const unsigned long warmuptime = 60000; // 1 min. +const unsigned long cooldowntime = 60000; // 1 min. MHZ19 mhz19 = MHZ19(rx_pin,tx_pin); LiquidCrystal lcd(7, 8, 9, 10, 11, 12); unsigned long time; +unsigned long lastwarntime = 0; int co2 = 0; int temp = 0; int lastppm = 0; @@ -87,12 +89,14 @@ void loop() 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) { + 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) { + if (co2 >= co2_warning_thr && lastppm < co2_warning_thr && time - lastwarntime > cooldowntime) { buzz(500, 1); + lastwarntime = time; } lcd.setCursor(0, 0); -- 2.39.5