Commit 42d90309 authored by Eric Duminil's avatar Eric Duminil
Browse files

LED Effects : small refactor, to allow breathing to be disabled (remove...

LED Effects : small refactor, to allow breathing to be disabled (remove MIN_BRIGHTNESS or set it to MAX_BRIGHTNESS).
parent b513c251
......@@ -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();
......
......@@ -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
/**
......
......@@ -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.
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment