Commit 14c90bc9 authored by Eric Duminil's avatar Eric Duminil
Browse files

LED Effects : small breathe refactor.

parent 42d90309
......@@ -138,7 +138,6 @@ namespace sensor {
*/
if (co2 < 2000) {
led_effects::displayCO2color(co2);
led_effects::breathe(co2);
delay(100);
} else {
// >= 2000: entire ring blinks red
......
......@@ -129,6 +129,19 @@ namespace led_effects {
}
}
/**
* If enabled, slowly varies the brightness between MAX_BRIGHTNESS & MIN_BRIGHTNESS.
*/
void breathe(int16_t co2) {
static uint8_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.
}
/**
* Fills the whole ring with green, yellow, orange or black, depending on co2 input and CO2_TICKS.
*/
......@@ -142,6 +155,9 @@ namespace led_effects {
pixels.setPixelColor(ledId, pixels.ColorHSV(LED_HUES[ledId], 255, brightness));
}
pixels.show();
if (config::brightness_amplitude > 0){
breathe(co2);
}
}
void showRainbowWheel(uint16_t duration_ms, uint16_t hue_increment) {
......@@ -177,18 +193,6 @@ namespace led_effects {
}
}
void breathe(int16_t co2) {
if (config::night_mode || config::brightness_amplitude == 0) {
return;
}
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.
}
/**
* Displays a complete blue circle, and starts removing LEDs one by one. Returns the number of remaining LEDs.
* Can be used for calibration, e.g. when countdown is 0. Does not work in night mode.
......
......@@ -25,7 +25,6 @@ namespace led_effects {
void setupRing();
void redAlert();
void breathe(int16_t co2);
int countdownToZero();
void showWaitingLED(uint32_t color);
void showKITTWheel(uint32_t color, uint16_t duration_s = 2);
......
Supports Markdown
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