diff --git a/ampel-firmware/co2_sensor.cpp b/ampel-firmware/co2_sensor.cpp index 7110776f7ab9362e431917afa8ebc84cd8bcb653..1ac7f9bbd267ed6365585069f532b880a9af4e13 100644 --- a/ampel-firmware/co2_sensor.cpp +++ b/ampel-firmware/co2_sensor.cpp @@ -133,11 +133,13 @@ namespace sensor { } /** * Display data, even if it's "old" (with breathing). - * Those effects include a short delay. + * A short delay is required in order to not overwhelm controller. + * see https://github.com/esp8266/Arduino/issues/3241#issuecomment-301290392 */ if (co2 < 2000) { led_effects::displayCO2color(co2); led_effects::breathe(co2); + delay(100); } else { // >= 2000: entire ring blinks red led_effects::redAlert(); diff --git a/ampel-firmware/config.public.h b/ampel-firmware/config.public.h index 00339350cf751165bbd1c1ac46f78ef859e46ed5..2fa008feaad9d10e545a2479b115bf0c6c2ee1a8 100644 --- a/ampel-firmware/config.public.h +++ b/ampel-firmware/config.public.h @@ -59,9 +59,10 @@ */ // LED brightness, which can vary between min and max brightness ("LED breathing") -// max_brightness should be between 0 and 255. -// min_brightness should be between 0 and max_brightness +// MAX_BRIGHTNESS should be between 0 and 255. # define MAX_BRIGHTNESS 255 +// MIN_BRIGHTNESS should be between 0 and MAX_BRIGHTNESS - 1 +// If MIN_BRIGHTNESS is not set, or set to MAX_BRIGHTNESS, breathing is disabled. # define MIN_BRIGHTNESS 60 /** diff --git a/ampel-firmware/led_effects.cpp b/ampel-firmware/led_effects.cpp index f654e77e581ec88bfce7c3dd8be9b648740e9583..4f84b3bfeb83f093e6ad4d844dfd124c5d1f27a1 100644 --- a/ampel-firmware/led_effects.cpp +++ b/ampel-firmware/led_effects.cpp @@ -4,16 +4,14 @@ *****************************************************************/ namespace config { const uint8_t max_brightness = MAX_BRIGHTNESS; - const uint8_t min_brightness = MIN_BRIGHTNESS; - const int kitt_tail = 3; // How many dimmer LEDs follow in K.I.T.T. wheel -} - -/***************************************************************** - * Configuration (calculated from above values) * - *****************************************************************/ -namespace config //NOTE: Use a class instead? NightMode could then be another state. -{ + #if defined(MIN_BRIGHTNESS) + const uint8_t min_brightness = MIN_BRIGHTNESS; + #else + const uint8_t min_brightness = MAX_BRIGHTNESS; + #endif const uint8_t brightness_amplitude = config::max_brightness - config::min_brightness; + const int kitt_tail = 3; // How many dimmer LEDs follow in K.I.T.T. wheel + //NOTE: Use a class instead? NightMode could then be another state. bool night_mode = false; } @@ -180,15 +178,15 @@ namespace led_effects { } void breathe(int16_t co2) { - if (!config::night_mode) { - static uint16_t breathing_offset = 0; - uint16_t brightness = config::min_brightness - + pixels.sine8(breathing_offset) * config::brightness_amplitude / 255; - pixels.setBrightness(brightness); - pixels.show(); - breathing_offset += 3; // breathing speed. +3 looks like slow human breathing. + if (config::night_mode || config::brightness_amplitude == 0) { + return; } - delay(co2 > 1600 ? 50 : 100); // faster breathing for higher CO2 values + static uint16_t breathing_offset = 0; + uint16_t brightness = config::min_brightness + + pixels.sine8(breathing_offset) * config::brightness_amplitude / 255; + pixels.setBrightness(brightness); + pixels.show(); + breathing_offset += co2 > 1600 ? 6 : 3; // breathing speed. +3 looks like slow human breathing. } /**