Commit 32fefdbe authored by Eric Duminil's avatar Eric Duminil
Browse files

Removing counter namespace

parent 9b11a49b
...@@ -34,12 +34,6 @@ const uint16_t CO2_TICKS[NUMPIXELS + 1] = { 0, 500, 600, 700, 800, 900, 1000, 12 ...@@ -34,12 +34,6 @@ const uint16_t CO2_TICKS[NUMPIXELS + 1] = { 0, 500, 600, 700, 800, 900, 1000, 12
const uint16_t LED_HUES[NUMPIXELS] = { 21845, 19114, 16383, 13653, 10922, 8191, 5461, 2730, 0, 0, 0, 0 }; // [hue angle] const uint16_t LED_HUES[NUMPIXELS] = { 21845, 19114, 16383, 13653, 10922, 8191, 5461, 2730, 0, 0, 0, 0 }; // [hue angle]
Adafruit_NeoPixel pixels(NUMPIXELS, NEOPIXELS_PIN, NEO_GRB + NEO_KHZ800); Adafruit_NeoPixel pixels(NUMPIXELS, NEOPIXELS_PIN, NEO_GRB + NEO_KHZ800);
namespace counter {
uint16_t wheel_offset = 0;
uint16_t kitt_offset = 0;
uint16_t breathing_offset = 0;
}
namespace LedEffects { namespace LedEffects {
//On-board LED on D4, aka GPIO02 //On-board LED on D4, aka GPIO02
const int ONBOARD_LED_PIN = 2; const int ONBOARD_LED_PIN = 2;
...@@ -84,13 +78,14 @@ namespace LedEffects { ...@@ -84,13 +78,14 @@ namespace LedEffects {
if (config::night_mode) { if (config::night_mode) {
return; return;
} }
static uint16_t kitt_offset = 0;
pixels.clear(); pixels.clear();
for (int j = config::kitt_tail; j >= 0; j--) { for (int j = config::kitt_tail; j >= 0; j--) {
int ledNumber = abs((counter::kitt_offset - j + NUMPIXELS) % (2 * NUMPIXELS) - NUMPIXELS) % NUMPIXELS; // Triangular function int ledNumber = abs((kitt_offset - j + NUMPIXELS) % (2 * NUMPIXELS) - NUMPIXELS) % NUMPIXELS; // Triangular function
pixels.setPixelColor(ledNumber, color * pixels.gamma8(255 - j * 76) / 255); pixels.setPixelColor(ledNumber, color * pixels.gamma8(255 - j * 76) / 255);
} }
pixels.show(); pixels.show();
counter::kitt_offset += 1; kitt_offset++;
} }
// Start K.I.T.T. led effect. Red color as default. // Start K.I.T.T. led effect. Red color as default.
...@@ -140,12 +135,13 @@ namespace LedEffects { ...@@ -140,12 +135,13 @@ namespace LedEffects {
if (config::night_mode) { if (config::night_mode) {
return; return;
} }
static uint16_t wheel_offset = 0;
unsigned long t0 = seconds(); unsigned long t0 = seconds();
pixels.setBrightness(config::max_brightness); pixels.setBrightness(config::max_brightness);
while (seconds() < t0 + duration_s) { while (seconds() < t0 + duration_s) {
for (int i = 0; i < NUMPIXELS; i++) { for (int i = 0; i < NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.ColorHSV(i * 65535 / NUMPIXELS + counter::wheel_offset)); pixels.setPixelColor(i, pixels.ColorHSV(i * 65535 / NUMPIXELS + wheel_offset));
counter::wheel_offset += hue_increment; wheel_offset += hue_increment;
} }
pixels.show(); pixels.show();
delay(10); delay(10);
...@@ -170,12 +166,12 @@ namespace LedEffects { ...@@ -170,12 +166,12 @@ namespace LedEffects {
void breathe(int16_t co2) { void breathe(int16_t co2) {
if (!config::night_mode) { if (!config::night_mode) {
static uint16_t breathing_offset = 0;
//TODO: use integer sine //TODO: use integer sine
pixels.setBrightness( pixels.setBrightness(
static_cast<int>(config::average_brightness static_cast<int>(config::average_brightness + cos(breathing_offset * 0.1) * config::brightness_amplitude));
+ cos(counter::breathing_offset * 0.1) * config::brightness_amplitude));
pixels.show(); pixels.show();
counter::breathing_offset += 1; breathing_offset++;
} }
delay(co2 > 1600 ? 50 : 100); // faster breathing for higher CO2 values delay(co2 > 1600 ? 50 : 100); // faster breathing for higher CO2 values
} }
......
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