Commit cdfe3b70 authored by Eric Duminil's avatar Eric Duminil
Browse files

Max and min brightness

parent c1fa76f3
Pipeline #5762 passed with stage
in 2 minutes and 5 seconds
#include "led_effects.h"
#include "config.h"
#include "web_config.h"
#include "sensor_console.h"
// Adafruit NeoPixel (Arduino library for controlling single-wire-based LED pixels and strip)
......@@ -12,13 +13,6 @@
* Configuration *
*****************************************************************/
namespace config {
const uint8_t max_brightness = MAX_BRIGHTNESS;
#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
const uint16_t poor_air_quality_ppm = 1600; // Above this threshold, LED breathing effect is faster.
bool display_led = true; // Will be set to false during "night mode".
......@@ -36,10 +30,41 @@ namespace config {
// LEDs >= 1600ppm will be pure red (hue angle 0°), LEDs in-between will be yellowish.
const uint16_t led_hues[led_count] = { 21845U, 19114U, 16383U, 13653U, 10922U, 8191U, 5461U, 2730U, 0, 0, 0, 0 }; // [hue angle]
#elif LED_COUNT == 16
const uint16_t co2_ticks[led_count + 1] = { 0, 500, 600, 700, 800, 900, 1000, 1100, 1200,
1300, 1400, 1500, 1600, 1700, 1800, 2000, 2200 }; // [ppm]
const uint16_t led_hues[led_count] = {21845U, 19859U, 17873U, 15887U, 13901U, 11915U, 9929U, 7943U,
5957U, 3971U, 1985U, 0, 0, 0, 0, 0}; // [hue angle]
const uint16_t co2_ticks[led_count + 1] = {
0,
500,
600,
700,
800,
900,
1000,
1100,
1200,
1300,
1400,
1500,
1600,
1700,
1800,
2000,
2200 }; // [ppm]
const uint16_t led_hues[led_count] = {
21845U,
19859U,
17873U,
15887U,
13901U,
11915U,
9929U,
7943U,
5957U,
3971U,
1985U,
0,
0,
0,
0,
0 }; // [hue angle]
#else
# error "Only 12 and 16 LEDs rings are currently supported."
#endif
......@@ -95,7 +120,7 @@ namespace led_effects {
void setupRing() {
pixels.begin();
pixels.setBrightness(config::max_brightness);
pixels.setBrightness(*config::max_brightness);
LEDsOff();
sensor_console::defineIntCommand("led", turnLEDsOnOff, F("0/1 (Turns LEDs on/off)"));
sensor_console::defineIntCommand("color", showColor, F("0xFF0015 (Shows color, specified as RGB, for debugging)"));
......@@ -136,7 +161,7 @@ namespace led_effects {
// Simulate a moving LED with tail. First LED starts at 0, and moves along a triangular function. The tail follows, with decreasing brightness.
// Takes approximately 1s for each direction.
void showKITTWheel(uint32_t color, uint16_t duration_s) {
pixels.setBrightness(config::max_brightness);
pixels.setBrightness(*config::max_brightness);
for (int i = 0; i < duration_s * config::led_count; ++i) {
showWaitingLED(color);
}
......@@ -165,7 +190,8 @@ namespace led_effects {
*/
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;
uint8_t brightness_amplitude = *config::max_brightness - *config::min_brightness;
uint16_t brightness = *config::min_brightness + pixels.sine8(breathing_offset) * brightness_amplitude / 255;
pixels.setBrightness(brightness);
pixels.show();
breathing_offset += co2 > config::poor_air_quality_ppm ? 6 : 3; // breathing speed. +3 looks like slow human breathing.
......@@ -178,13 +204,13 @@ namespace led_effects {
if (!config::display_led) {
return;
}
pixels.setBrightness(config::max_brightness);
pixels.setBrightness(*config::max_brightness);
for (int ledId = 0; ledId < config::led_count; ++ledId) {
uint8_t brightness = getLedBrightness(co2, ledId);
pixels.setPixelColor(ledId, pixels.ColorHSV(config::led_hues[ledId], 255, brightness));
}
pixels.show();
if (config::brightness_amplitude > 0) {
if (*config::max_brightness > *config::min_brightness) {
breathe(co2);
}
}
......@@ -196,7 +222,7 @@ namespace led_effects {
static uint16_t wheel_offset = 0;
static uint16_t sine_offset = 0;
unsigned long t0 = millis();
pixels.setBrightness(config::max_brightness);
pixels.setBrightness(*config::max_brightness);
while (millis() - t0 < duration_ms) {
for (int i = 0; i < config::led_count; i++) {
pixels.setPixelColor(i, pixels.ColorHSV(i * 65535 / config::led_count + wheel_offset));
......@@ -216,7 +242,7 @@ namespace led_effects {
return;
}
for (int i = 0; i < 10; i++) {
pixels.setBrightness(static_cast<int>(config::max_brightness * (1 - i * 0.1)));
pixels.setBrightness(static_cast<int>(*config::max_brightness * (1 - i * 0.1)));
delay(50);
pixels.fill(color::red);
pixels.show();
......
......@@ -272,11 +272,14 @@ namespace web_config {
namespace config {
// CSV
uint16_t *csv_interval = &web_config::csvTimestepParam.value();
// Sensor
uint16_t *measurement_timestep = &web_config::timestepParam.value(); // [s] Value between 2 and 1800 (range for SCD30 sensor).
uint16_t *altitude_above_sea_level = &web_config::altitudeParam.value(); // [m]
uint16_t *co2_calibration_level = &web_config::atmosphericCO2Param.value(); // [ppm]
bool *auto_calibrate_sensor = &web_config::autoCalibrateParam.value(); // [true / false]
float *temperature_offset = &web_config::temperatureOffsetParam.value(); // [K] Sign isn't relevant.
}
\ No newline at end of file
uint8_t *max_brightness = &web_config::maxBrightnessParam.value();
uint8_t *min_brightness = &web_config::minBrightnessParam.value();
}
......@@ -18,6 +18,10 @@ namespace config {
extern uint16_t *co2_calibration_level; // [ppm]
extern bool *auto_calibrate_sensor; // [true / false]
extern float *temperature_offset; // [K] Sign isn't relevant.
// LED
extern uint8_t *max_brightness;
extern uint8_t *min_brightness;
}
namespace web_config {
......
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