From 37d287276f55ae9a6807511ff86b6291fed68b0d Mon Sep 17 00:00:00 2001 From: Alexander Gabriel Date: Fri, 20 Nov 2020 23:43:48 +0100 Subject: [PATCH] Shows Status on Neopixels --- BME680-TTN.ino | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/BME680-TTN.ino b/BME680-TTN.ino index 3495f96..f7d92de 100644 --- a/BME680-TTN.ino +++ b/BME680-TTN.ino @@ -4,8 +4,8 @@ #define USE_DISPLAY #ifdef USE_DISPLAY -#include +#include #ifdef U8X8_HAVE_HW_SPI #include #endif @@ -13,6 +13,11 @@ #include #endif +#include +#define LED_PIN 18 +#define LED_COUNT 8 +Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); + //U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 15, /* data=*/ 4, /* reset=*/ 16); U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 15, /* data=*/ 4, /* reset=*/ 16); #endif @@ -20,6 +25,8 @@ U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 15, /* data=*/ 4, int DisplayUpdateLoopInterval = 1000; uint32_t DisplayUpdateLoopMillis = millis() - DisplayUpdateLoopInterval; +int NeoPixelUpdateLoopInterval = 1000; +uint32_t NeoPixelUpdateLoopMillis = millis() - NeoPixelUpdateLoopInterval; // Create an object of the class Bsec Bsec iaqSensor; @@ -62,7 +69,9 @@ void setup(void) output = "Timestamp [ms], raw temperature [°C], pressure [hPa], raw relative humidity [%], gas [Ohm], IAQ, IAQ accuracy, temperature [°C], relative humidity [%], Static IAQ, CO2 equivalent, breath VOC equivalent"; Serial.println(output); - + strip.begin(); + strip.show(); + strip.setBrightness(50); } // Function that is looped forever @@ -89,6 +98,7 @@ void loop(void) #ifdef USE_DISPLAY updateDisplay(); #endif + updateNeoPixel(); } // Helper function definitions @@ -161,4 +171,25 @@ void updateDisplay() { u8g2.sendBuffer(); } } -#endif \ No newline at end of file +#endif + +void updateNeoPixel(){ + if(millis() - NeoPixelUpdateLoopMillis > NeoPixelUpdateLoopInterval) { + NeoPixelUpdateLoopMillis = millis(); + double warningValue = 800; + double criticalValue = 1500; + double steps = 2000/strip.numPixels(); + float co2 = iaqSensor.co2Equivalent; + for(int i=0; i= steps*(i+1)) { + if(co2 >= criticalValue) strip.setPixelColor(i, 255, 0, 0); + else if(co2 >= warningValue) strip.setPixelColor(i, 255, 165, 0); + else if(co2 < warningValue) strip.setPixelColor(i, 0, 255, 0); + } + else { + strip.setPixelColor(i, 0, 0, 0); + } + strip.show(); + } + } +} \ No newline at end of file