X-Git-Url: https://git.toastfreeware.priv.at/toast/airingbutler.git/blobdiff_plain/b4d3ce956ec69c81f240e37aa4f381533c4b6c73..e9898a8dd32afa327d954ebe4adbeb9c856f3b23:/airingbutler.ino diff --git a/airingbutler.ino b/airingbutler.ino index c05a737..c93f4ba 100644 --- a/airingbutler.ino +++ b/airingbutler.ino @@ -11,20 +11,11 @@ const int led_red_pin = 6; const int buzzer_pin = 13; -/* -const int lcd_pin = 7; -const int lcd_pin = 8; -const int lcd_pin = 9; -const int lcd_pin = 10; -const int lcd_pin = 11; -const int lcd_pin = 12; -*/ - const int co2_warning_thr = 1000; const int co2_alarm_thr = 1500; MHZ19 mhz19 = MHZ19(rx_pin,tx_pin); -LiquidCrystal lcd(7,8,9,10,11,12); +LiquidCrystal lcd(7, 8, 9, 10, 11, 12); unsigned long time; int lastppm = 0; @@ -32,9 +23,11 @@ int lastppm = 0; void setup() { - Serial.begin(115200); - Serial.println("Time,CO2,Temp"); - mhz19.begin(rx_pin, tx_pin); + Serial.begin(115200); + Serial.println("Time,CO2,Temp"); + + // MH-Z19 + mhz19.begin(rx_pin, tx_pin); // LCD lcd.begin(16,2); @@ -43,7 +36,7 @@ void setup() lcd.setCursor(0,1); lcd.print("says hello!"); - // led+buzzer + // LEDs + buzzer pinMode(led_green_pin, OUTPUT); pinMode(led_yellow_pin, OUTPUT); pinMode(led_red_pin, OUTPUT); @@ -60,22 +53,22 @@ void setup() digitalWrite(buzzer_pin, HIGH); delay(200); digitalWrite(buzzer_pin, LOW); - + lcd.clear(); } void loop() { - time = millis(); - measurement_t m = mhz19.getMeasurement(); - - Serial.print(time); - Serial.print(","); - Serial.print(m.co2_ppm); - Serial.print(","); - Serial.println(m.temperature); - + time = millis(); + measurement_t m = mhz19.getMeasurement(); + + Serial.print(time); + Serial.print(","); + Serial.print(m.co2_ppm); + Serial.print(","); + Serial.println(m.temperature); + digitalWrite(led_red_pin, m.co2_ppm >= co2_alarm_thr); digitalWrite(led_yellow_pin, m.co2_ppm >= co2_warning_thr && m.co2_ppm < co2_alarm_thr); digitalWrite(led_green_pin, m.co2_ppm < co2_warning_thr); @@ -100,11 +93,11 @@ void loop() digitalWrite(buzzer_pin, LOW); } - lcd.setCursor(0,0); + lcd.setCursor(0, 0); lcd.print("CO2: "); lcd.print(m.co2_ppm); lcd.print(" ppm "); - lastppm = m.co2_ppm; - delay(5000); + lastppm = m.co2_ppm; + delay(5000); }