overlay function added (analog clock)

lock individual leds in WS2812FX library
This commit is contained in:
cschwinne 2016-12-31 00:38:51 +01:00
parent 40a853aadb
commit 31e3daf3e3
14 changed files with 388 additions and 55 deletions

View File

@ -74,7 +74,7 @@ void WS2812FX::setMode(uint8_t m) {
_mode_index = constrain(m, 0, MODE_COUNT-1);
_mode_color = _color;
Adafruit_NeoPixel::setBrightness(_brightness);
strip_off();
strip_off_respectLock();
}
void WS2812FX::setSpeed(uint8_t s) {
@ -82,7 +82,7 @@ void WS2812FX::setSpeed(uint8_t s) {
_counter_mode_step = 0;
_mode_last_call_time = 0;
_speed = constrain(s, SPEED_MIN, SPEED_MAX);
strip_off();
strip_off_respectLock();
}
void WS2812FX::increaseSpeed(uint8_t s) {
@ -167,6 +167,14 @@ void WS2812FX::strip_off() {
Adafruit_NeoPixel::show();
}
void WS2812FX::strip_off_respectLock() {
for(uint16_t i=0; i < _led_count; i++) {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, 0);
}
Adafruit_NeoPixel::show();
}
/*
* Put a value 0 to 255 in to get a color value.
@ -212,11 +220,12 @@ uint8_t WS2812FX::get_random_wheel_index(uint8_t pos) {
*/
void WS2812FX::mode_static(void) {
for(uint16_t i=0; i < _led_count; i++) {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, _color);
}
Adafruit_NeoPixel::show();
_mode_delay = 50;
_mode_delay = 25;
}
@ -226,11 +235,12 @@ void WS2812FX::mode_static(void) {
void WS2812FX::mode_blink(void) {
if(_counter_mode_call % 2 == 1) {
for(uint16_t i=0; i < _led_count; i++) {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, _color);
}
Adafruit_NeoPixel::show();
} else {
strip_off();
strip_off_respectLock();
}
_mode_delay = 100 + ((1986 * (uint32_t)(SPEED_MAX - _speed)) / SPEED_MAX);
@ -243,8 +253,10 @@ void WS2812FX::mode_blink(void) {
*/
void WS2812FX::mode_color_wipe(void) {
if(_counter_mode_step < _led_count) {
if (!_locked[_counter_mode_step])
Adafruit_NeoPixel::setPixelColor(_counter_mode_step, _color);
} else {
if (!_locked[_counter_mode_step - _led_count])
Adafruit_NeoPixel::setPixelColor(_counter_mode_step - _led_count, 0);
}
Adafruit_NeoPixel::show();
@ -263,7 +275,7 @@ void WS2812FX::mode_color_wipe_random(void) {
if(_counter_mode_step == 0) {
_mode_color = get_random_wheel_index(_mode_color);
}
if (!_locked[_counter_mode_step])
Adafruit_NeoPixel::setPixelColor(_counter_mode_step, color_wheel(_mode_color));
Adafruit_NeoPixel::show();
@ -281,6 +293,7 @@ void WS2812FX::mode_random_color(void) {
_mode_color = get_random_wheel_index(_mode_color);
for(uint16_t i=0; i < _led_count; i++) {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, color_wheel(_mode_color));
}
@ -296,11 +309,13 @@ void WS2812FX::mode_random_color(void) {
void WS2812FX::mode_single_dynamic(void) {
if(_counter_mode_call == 0) {
for(uint16_t i=0; i < _led_count; i++) {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, color_wheel(random(256)));
}
}
Adafruit_NeoPixel::setPixelColor(random(_led_count), color_wheel(random(256)));
int ran = random(_led_count);
if (!_locked[ran])
Adafruit_NeoPixel::setPixelColor(ran, color_wheel(random(256)));
Adafruit_NeoPixel::show();
_mode_delay = 10 + ((5000 * (uint32_t)(SPEED_MAX - _speed)) / SPEED_MAX);
}
@ -312,6 +327,7 @@ void WS2812FX::mode_single_dynamic(void) {
*/
void WS2812FX::mode_multi_dynamic(void) {
for(uint16_t i=0; i < _led_count; i++) {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, color_wheel(random(256)));
}
Adafruit_NeoPixel::show();
@ -346,6 +362,7 @@ void WS2812FX::mode_breath(void) {
}
for(uint16_t i=0; i < _led_count; i++) {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, _color); // set all LEDs to selected color
}
int b = map(breath_brightness, 0, 255, 0, _brightness); // keep brightness below brightness set by user
@ -362,6 +379,7 @@ void WS2812FX::mode_breath(void) {
*/
void WS2812FX::mode_fade(void) {
for(uint16_t i=0; i < _led_count; i++) {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, _color);
}
@ -388,7 +406,11 @@ void WS2812FX::mode_scan(void) {
int i = _counter_mode_step - (_led_count - 1);
i = abs(i);
Adafruit_NeoPixel::clear();
for(uint16_t x=0; x < _led_count; x++) {
if (!_locked[x])
Adafruit_NeoPixel::setPixelColor(x, 0);
}
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(abs(i), _color);
Adafruit_NeoPixel::show();
@ -407,9 +429,13 @@ void WS2812FX::mode_dual_scan(void) {
int i = _counter_mode_step - (_led_count - 1);
i = abs(i);
Adafruit_NeoPixel::clear();
for(uint16_t x=0; x < _led_count; x++) {
if (!_locked[x])
Adafruit_NeoPixel::setPixelColor(x, 0);
}
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, _color);
if (!_locked[_led_count - (i+1)])
Adafruit_NeoPixel::setPixelColor(_led_count - (i+1), _color);
Adafruit_NeoPixel::show();
@ -423,6 +449,7 @@ void WS2812FX::mode_dual_scan(void) {
void WS2812FX::mode_rainbow(void) {
uint32_t color = color_wheel(_counter_mode_step);
for(uint16_t i=0; i < _led_count; i++) {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, color);
}
Adafruit_NeoPixel::show();
@ -438,6 +465,7 @@ void WS2812FX::mode_rainbow(void) {
*/
void WS2812FX::mode_rainbow_cycle(void) {
for(uint16_t i=0; i < _led_count; i++) {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, color_wheel(((i * 256 / _led_count) + _counter_mode_step) % 256));
}
Adafruit_NeoPixel::show();
@ -456,12 +484,14 @@ void WS2812FX::mode_theater_chase(void) {
uint8_t j = _counter_mode_call % 6;
if(j % 2 == 0) {
for(uint16_t i=0; i < _led_count; i=i+3) {
if (!_locked[i+(j/2)])
Adafruit_NeoPixel::setPixelColor(i+(j/2), _color);
}
Adafruit_NeoPixel::show();
_mode_delay = 50 + ((500 * (uint32_t)(SPEED_MAX - _speed)) / SPEED_MAX);
} else {
for(uint16_t i=0; i < _led_count; i=i+3) {
if (!_locked[i+(j/2)])
Adafruit_NeoPixel::setPixelColor(i+(j/2), 0);
}
_mode_delay = 1;
@ -477,12 +507,14 @@ void WS2812FX::mode_theater_chase_rainbow(void) {
uint8_t j = _counter_mode_call % 6;
if(j % 2 == 0) {
for(uint16_t i=0; i < _led_count; i=i+3) {
if (!_locked[i+(j/2)])
Adafruit_NeoPixel::setPixelColor(i+(j/2), color_wheel((i+_counter_mode_step) % 256));
}
Adafruit_NeoPixel::show();
_mode_delay = 50 + ((500 * (uint32_t)(SPEED_MAX - _speed)) / SPEED_MAX);
} else {
for(uint16_t i=0; i < _led_count; i=i+3) {
if (!_locked[i+(j/2)])
Adafruit_NeoPixel::setPixelColor(i+(j/2), 0);
}
_mode_delay = 1;
@ -501,7 +533,8 @@ void WS2812FX::mode_running_lights(void) {
for(uint16_t i=0; i < _led_count; i++) {
int s = (sin(i+_counter_mode_call) * 127) + 128;
Adafruit_NeoPixel::setPixelColor(i, (((uint32_t)(r * s)) / 255), (((uint32_t)(g * s)) / 255), (((uint32_t)(b * s)) / 255));
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, (((uint32_t)(r * s)) / 255), (((uint32_t)(g * s)) / 255), (((uint32_t)(b * s)) / 255));
}
Adafruit_NeoPixel::show();
@ -521,8 +554,9 @@ void WS2812FX::mode_twinkle(void) {
uint16_t max_leds = max(1, _led_count/2); // make sure, at least one LED is on
_counter_mode_step = random(min_leds, max_leds);
}
Adafruit_NeoPixel::setPixelColor(random(_led_count), _mode_color);
int ran = random(_led_count);
if (!_locked[ran])
Adafruit_NeoPixel::setPixelColor(ran, _mode_color);
Adafruit_NeoPixel::show();
_counter_mode_step--;
@ -556,12 +590,14 @@ void WS2812FX::mode_twinkle_fade(void) {
px_r = px_r >> 1;
px_g = px_g >> 1;
px_b = px_b >> 1;
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, px_r, px_g, px_b);
}
if(random(3) == 0) {
Adafruit_NeoPixel::setPixelColor(random(_led_count), _mode_color);
int ran = random(_led_count);
if (!_locked[ran])
Adafruit_NeoPixel::setPixelColor(ran, _mode_color);
}
Adafruit_NeoPixel::show();
@ -584,8 +620,13 @@ void WS2812FX::mode_twinkle_fade_random(void) {
* Inspired by www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/
*/
void WS2812FX::mode_sparkle(void) {
Adafruit_NeoPixel::clear();
Adafruit_NeoPixel::setPixelColor(random(_led_count),_color);
for(uint16_t i=0; i < _led_count; i++) {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, 0);
}
int ran = random(_led_count);
if (!_locked[ran])
Adafruit_NeoPixel::setPixelColor(ran ,_color);
Adafruit_NeoPixel::show();
_mode_delay = 10 + ((200 * (uint32_t)(SPEED_MAX - _speed)) / SPEED_MAX);
}
@ -597,11 +638,14 @@ void WS2812FX::mode_sparkle(void) {
*/
void WS2812FX::mode_flash_sparkle(void) {
for(uint16_t i=0; i < _led_count; i++) {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, _color);
}
if(random(10) == 7) {
Adafruit_NeoPixel::setPixelColor(random(_led_count), 255, 255, 255);
int ran = random(_led_count);
if (!_locked[ran])
Adafruit_NeoPixel::setPixelColor(ran , 255, 255, 255);
_mode_delay = 20;
} else {
_mode_delay = 20 + ((200 * (uint32_t)(SPEED_MAX - _speed)) / SPEED_MAX);
@ -617,18 +661,20 @@ void WS2812FX::mode_flash_sparkle(void) {
*/
void WS2812FX::mode_hyper_sparkle(void) {
for(uint16_t i=0; i < _led_count; i++) {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, _color);
}
if(random(10) < 4) {
for(uint16_t i=0; i < max(1, _led_count/3); i++) {
Adafruit_NeoPixel::setPixelColor(random(_led_count), 255, 255, 255);
int ran = random(_led_count);
if (!_locked[ran])
Adafruit_NeoPixel::setPixelColor(ran , 255, 255, 255);
}
_mode_delay = 20;
} else {
_mode_delay = 15 + ((120 * (uint32_t)(SPEED_MAX - _speed)) / SPEED_MAX);
}
Adafruit_NeoPixel::show();
}
@ -639,11 +685,13 @@ void WS2812FX::mode_hyper_sparkle(void) {
void WS2812FX::mode_strobe(void) {
if(_counter_mode_call % 2 == 0) {
for(uint16_t i=0; i < _led_count; i++) {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, _color);
}
_mode_delay = 20;
} else {
for(uint16_t i=0; i < _led_count; i++) {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, 0);
}
_mode_delay = 50 + ((1986 * (uint32_t)(SPEED_MAX - _speed)) / SPEED_MAX);
@ -653,16 +701,18 @@ void WS2812FX::mode_strobe(void) {
/*
* Strobe effect with different strobe count and pause, controled by _speed.
* Strobe effect with different strobe count and pause, controlled by _speed.
*/
void WS2812FX::mode_multi_strobe(void) {
for(uint16_t i=0; i < _led_count; i++) {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, 0);
}
if(_counter_mode_step < (2 * ((_speed / 10) + 1))) {
if(_counter_mode_step % 2 == 0) {
for(uint16_t i=0; i < _led_count; i++) {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, _color);
}
_mode_delay = 20;
@ -685,11 +735,13 @@ void WS2812FX::mode_multi_strobe(void) {
void WS2812FX::mode_strobe_rainbow(void) {
if(_counter_mode_call % 2 == 0) {
for(uint16_t i=0; i < _led_count; i++) {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, color_wheel(_counter_mode_call % 256));
}
_mode_delay = 20;
} else {
for(uint16_t i=0; i < _led_count; i++) {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, 0);
}
_mode_delay = 50 + ((1986 * (uint32_t)(SPEED_MAX - _speed)) / SPEED_MAX);
@ -704,6 +756,7 @@ void WS2812FX::mode_strobe_rainbow(void) {
void WS2812FX::mode_blink_rainbow(void) {
if(_counter_mode_call % 2 == 1) {
for(uint16_t i=0; i < _led_count; i++) {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, color_wheel(_counter_mode_call % 256));
}
Adafruit_NeoPixel::show();
@ -720,12 +773,15 @@ void WS2812FX::mode_blink_rainbow(void) {
*/
void WS2812FX::mode_chase_white(void) {
for(uint16_t i=0; i < _led_count; i++) {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, 255, 255, 255);
}
uint16_t n = _counter_mode_step;
uint16_t m = (_counter_mode_step + 1) % _led_count;
if (!_locked[n])
Adafruit_NeoPixel::setPixelColor(n, _color);
if (!_locked[m])
Adafruit_NeoPixel::setPixelColor(m, _color);
Adafruit_NeoPixel::show();
@ -739,12 +795,15 @@ void WS2812FX::mode_chase_white(void) {
*/
void WS2812FX::mode_chase_color(void) {
for(uint16_t i=0; i < _led_count; i++) {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, _color);
}
uint16_t n = _counter_mode_step;
uint16_t m = (_counter_mode_step + 1) % _led_count;
if (!_locked[n])
Adafruit_NeoPixel::setPixelColor(n, 255, 255, 255);
if (!_locked[m])
Adafruit_NeoPixel::setPixelColor(m, 255, 255, 255);
Adafruit_NeoPixel::show();
@ -758,17 +817,21 @@ void WS2812FX::mode_chase_color(void) {
*/
void WS2812FX::mode_chase_random(void) {
if(_counter_mode_step == 0) {
if (!_locked[_led_count-1])
Adafruit_NeoPixel::setPixelColor(_led_count-1, color_wheel(_mode_color));
_mode_color = get_random_wheel_index(_mode_color);
}
for(uint16_t i=0; i < _counter_mode_step; i++) {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, color_wheel(_mode_color));
}
uint16_t n = _counter_mode_step;
uint16_t m = (_counter_mode_step + 1) % _led_count;
if (!_locked[n])
Adafruit_NeoPixel::setPixelColor(n, 255, 255, 255);
if (!_locked[m])
Adafruit_NeoPixel::setPixelColor(m, 255, 255, 255);
Adafruit_NeoPixel::show();
@ -783,12 +846,15 @@ void WS2812FX::mode_chase_random(void) {
*/
void WS2812FX::mode_chase_rainbow(void) {
for(uint16_t i=0; i < _led_count; i++) {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, color_wheel(((i * 256 / _led_count) + (_counter_mode_call % 256)) % 256));
}
uint16_t n = _counter_mode_step;
uint16_t m = (_counter_mode_step + 1) % _led_count;
if (!_locked[n])
Adafruit_NeoPixel::setPixelColor(n, 255, 255, 255);
if (!_locked[m])
Adafruit_NeoPixel::setPixelColor(m, 255, 255, 255);
Adafruit_NeoPixel::show();
@ -805,6 +871,7 @@ void WS2812FX::mode_chase_flash(void) {
uint8_t flash_step = _counter_mode_call % ((flash_count * 2) + 1);
for(uint16_t i=0; i < _led_count; i++) {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, _color);
}
@ -812,7 +879,9 @@ void WS2812FX::mode_chase_flash(void) {
if(flash_step % 2 == 0) {
uint16_t n = _counter_mode_step;
uint16_t m = (_counter_mode_step + 1) % _led_count;
if (!_locked[n])
Adafruit_NeoPixel::setPixelColor(n, 255, 255, 255);
if (!_locked[m])
Adafruit_NeoPixel::setPixelColor(m, 255, 255, 255);
_mode_delay = 20;
} else {
@ -835,6 +904,7 @@ void WS2812FX::mode_chase_flash_random(void) {
uint8_t flash_step = _counter_mode_call % ((flash_count * 2) + 1);
for(uint16_t i=0; i < _counter_mode_step; i++) {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, color_wheel(_mode_color));
}
@ -842,11 +912,15 @@ void WS2812FX::mode_chase_flash_random(void) {
uint16_t n = _counter_mode_step;
uint16_t m = (_counter_mode_step + 1) % _led_count;
if(flash_step % 2 == 0) {
if (!_locked[n])
Adafruit_NeoPixel::setPixelColor(n, 255, 255, 255);
if (!_locked[m])
Adafruit_NeoPixel::setPixelColor(m, 255, 255, 255);
_mode_delay = 20;
} else {
if (!_locked[n])
Adafruit_NeoPixel::setPixelColor(n, color_wheel(_mode_color));
if (!_locked[m])
Adafruit_NeoPixel::setPixelColor(m, 0, 0, 0);
_mode_delay = 30;
}
@ -868,12 +942,15 @@ void WS2812FX::mode_chase_flash_random(void) {
*/
void WS2812FX::mode_chase_rainbow_white(void) {
for(uint16_t i=0; i < _led_count; i++) {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, 255, 255, 255);
}
uint16_t n = _counter_mode_step;
uint16_t m = (_counter_mode_step + 1) % _led_count;
if (!_locked[n])
Adafruit_NeoPixel::setPixelColor(n, color_wheel(((n * 256 / _led_count) + (_counter_mode_call % 256)) % 256));
if (!_locked[m])
Adafruit_NeoPixel::setPixelColor(m, color_wheel(((m * 256 / _led_count) + (_counter_mode_call % 256)) % 256));
Adafruit_NeoPixel::show();
@ -887,12 +964,15 @@ void WS2812FX::mode_chase_rainbow_white(void) {
*/
void WS2812FX::mode_chase_blackout(void) {
for(uint16_t i=0; i < _led_count; i++) {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, _color);
}
uint16_t n = _counter_mode_step;
uint16_t m = (_counter_mode_step + 1) % _led_count;
if (!_locked[n])
Adafruit_NeoPixel::setPixelColor(n, 0, 0, 0);
if (!_locked[m])
Adafruit_NeoPixel::setPixelColor(m, 0, 0, 0);
Adafruit_NeoPixel::show();
@ -906,12 +986,15 @@ void WS2812FX::mode_chase_blackout(void) {
*/
void WS2812FX::mode_chase_blackout_rainbow(void) {
for(uint16_t i=0; i < _led_count; i++) {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, color_wheel(((i * 256 / _led_count) + (_counter_mode_call % 256)) % 256));
}
uint16_t n = _counter_mode_step;
uint16_t m = (_counter_mode_step + 1) % _led_count;
if (!_locked[n])
Adafruit_NeoPixel::setPixelColor(n, 0, 0, 0);
if (!_locked[m])
Adafruit_NeoPixel::setPixelColor(m, 0, 0, 0);
Adafruit_NeoPixel::show();
@ -929,8 +1012,10 @@ void WS2812FX::mode_color_sweep_random(void) {
}
if(_counter_mode_step < _led_count) {
if (!_locked[_counter_mode_step])
Adafruit_NeoPixel::setPixelColor(_counter_mode_step, color_wheel(_mode_color));
} else {
if (!_locked[(_led_count * 2) - _counter_mode_step - 1])
Adafruit_NeoPixel::setPixelColor((_led_count * 2) - _counter_mode_step - 1, color_wheel(_mode_color));
}
Adafruit_NeoPixel::show();
@ -946,8 +1031,10 @@ void WS2812FX::mode_color_sweep_random(void) {
void WS2812FX::mode_running_color(void) {
for(uint16_t i=0; i < _led_count; i++) {
if((i + _counter_mode_step) % 4 < 2) {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, _mode_color);
} else {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, 255, 255, 255);
}
}
@ -964,8 +1051,10 @@ void WS2812FX::mode_running_color(void) {
void WS2812FX::mode_running_red_blue(void) {
for(uint16_t i=0; i < _led_count; i++) {
if((i + _counter_mode_step) % 4 < 2) {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, 255, 0, 0);
} else {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, 0, 0, 255);
}
}
@ -981,11 +1070,21 @@ void WS2812FX::mode_running_red_blue(void) {
*/
void WS2812FX::mode_running_random(void) {
for(uint16_t i=_led_count-1; i > 0; i--) {
Adafruit_NeoPixel::setPixelColor(i, Adafruit_NeoPixel::getPixelColor(i-1));
if (!_locked[i])
{
if (!_locked[i-1])
{
Adafruit_NeoPixel::setPixelColor(i, Adafruit_NeoPixel::getPixelColor(i-1));
} else
{
Adafruit_NeoPixel::setPixelColor(i, color_wheel(_mode_color));
}
}
}
if(_counter_mode_step == 0) {
_mode_color = get_random_wheel_index(_mode_color);
if (!_locked[0])
Adafruit_NeoPixel::setPixelColor(0, color_wheel(_mode_color));
}
@ -1014,6 +1113,7 @@ void WS2812FX::mode_larson_scanner(void) {
px_g = px_g >> 1;
px_b = px_b >> 1;
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, px_r, px_g, px_b);
}
@ -1025,6 +1125,7 @@ void WS2812FX::mode_larson_scanner(void) {
pos = (_led_count * 2) - _counter_mode_step - 2;
}
if (!_locked[pos])
Adafruit_NeoPixel::setPixelColor(pos, _color);
Adafruit_NeoPixel::show();
@ -1050,9 +1151,11 @@ void WS2812FX::mode_comet(void) {
px_g = px_g >> 1;
px_b = px_b >> 1;
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, px_r, px_g, px_b);
}
if (!_locked[_counter_mode_step])
Adafruit_NeoPixel::setPixelColor(_counter_mode_step, _color);
Adafruit_NeoPixel::show();
@ -1082,6 +1185,7 @@ void WS2812FX::mode_fireworks(void) {
px_g = px_g >> 1;
px_b = px_b >> 1;
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, px_r, px_g, px_b);
}
@ -1089,6 +1193,7 @@ void WS2812FX::mode_fireworks(void) {
px_r = (((Adafruit_NeoPixel::getPixelColor(1) & 0x00FF0000) >> 16) >> 1) + ((Adafruit_NeoPixel::getPixelColor(0) & 0x00FF0000) >> 16);
px_g = (((Adafruit_NeoPixel::getPixelColor(1) & 0x0000FF00) >> 8) >> 1) + ((Adafruit_NeoPixel::getPixelColor(0) & 0x0000FF00) >> 8);
px_b = (((Adafruit_NeoPixel::getPixelColor(1) & 0x000000FF) >> 0) >> 1) + ((Adafruit_NeoPixel::getPixelColor(0) & 0x000000FF) >> 0);
if (!_locked[0])
Adafruit_NeoPixel::setPixelColor(0, px_r, px_g, px_b);
// set brightness(i) = ((brightness(i-1)/2 + brightness(i+1)) / 2) + brightness(i)
@ -1108,6 +1213,7 @@ void WS2812FX::mode_fireworks(void) {
(((Adafruit_NeoPixel::getPixelColor(i+1) & 0x000000FF) >> 0) >> 0) ) >> 1) +
(((Adafruit_NeoPixel::getPixelColor(i ) & 0x000000FF) >> 0) >> 0);
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, px_r, px_g, px_b);
}
@ -1115,10 +1221,13 @@ void WS2812FX::mode_fireworks(void) {
px_r = (((Adafruit_NeoPixel::getPixelColor(_led_count-2) & 0x00FF0000) >> 16) >> 2) + ((Adafruit_NeoPixel::getPixelColor(_led_count-1) & 0x00FF0000) >> 16);
px_g = (((Adafruit_NeoPixel::getPixelColor(_led_count-2) & 0x0000FF00) >> 8) >> 2) + ((Adafruit_NeoPixel::getPixelColor(_led_count-1) & 0x0000FF00) >> 8);
px_b = (((Adafruit_NeoPixel::getPixelColor(_led_count-2) & 0x000000FF) >> 0) >> 2) + ((Adafruit_NeoPixel::getPixelColor(_led_count-1) & 0x000000FF) >> 0);
if (!_locked[_led_count-1])
Adafruit_NeoPixel::setPixelColor(_led_count-1, px_r, px_g, px_b);
for(uint16_t i=0; i<max(1,_led_count/20); i++) {
if(random(10) == 0) {
int ran = random(_led_count);
if (!_locked[ran])
Adafruit_NeoPixel::setPixelColor(random(_led_count), _mode_color);
}
}
@ -1144,8 +1253,10 @@ void WS2812FX::mode_fireworks_random(void) {
void WS2812FX::mode_merry_christmas(void) {
for(uint16_t i=0; i < _led_count; i++) {
if((i + _counter_mode_step) % 4 < 2) {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, 255, 0, 0);
} else {
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i, 0, 255, 0);
}
}
@ -1184,38 +1295,142 @@ void WS2812FX::mode_fire_flicker_int(int rev_intensity)
if(g1<0) g1=0;
if(r1<0) r1=0;
if(b1<0) b1=0;
if (!_locked[i])
Adafruit_NeoPixel::setPixelColor(i,r1,g1, b1);
}
Adafruit_NeoPixel::show();
_mode_delay = 10 + ((500 * (uint32_t)(SPEED_MAX - _speed)) / SPEED_MAX);
}
/*
* Access to individual control
*/
void WS2812FX::mode_individual_control(void)
{
//does nothing
_mode_delay = 50;
}
/*
* Only works in individual mode
*/
void WS2812FX::setIndividual(int i)
{
if (i >= 0 && i < _led_count)
Adafruit_NeoPixel::setPixelColor(i, _color);
Adafruit_NeoPixel::show();
{
Adafruit_NeoPixel::setPixelColor(i, _color);
//Adafruit_NeoPixel::show();
_locked[i] = true;
}
}
void WS2812FX::setIndividual(int i, uint32_t col)
{
if (i >= 0 && i < _led_count)
{
Adafruit_NeoPixel::setPixelColor(i, col);
//Adafruit_NeoPixel::show();
_locked[i] = true;
}
}
void WS2812FX::setRange(int i, int i2)
{
if (i2 >= i)
{
for (int x = i; x <= i2; x++)
{
if (x >= 0 && x < _led_count)
{
Adafruit_NeoPixel::setPixelColor(x, _color);
_locked[x] = true;
}
}
} else
{
for (int x = i2; x < _led_count; x++)
{
if (x >= 0 && x < _led_count)
{
Adafruit_NeoPixel::setPixelColor(x, _color);
_locked[x] = true;
}
}
for (int x = 0; x <= i; x++)
{
if (x >= 0 && x < _led_count)
{
Adafruit_NeoPixel::setPixelColor(x, _color);
_locked[x] = true;
}
}
}
//Adafruit_NeoPixel::show();
}
void WS2812FX::setRange(int i, int i2, uint32_t col)
{
if (i2 >= i)
{
for (int x = i; x <= i2; x++)
{
if (x >= 0 && x < _led_count)
{
Adafruit_NeoPixel::setPixelColor(x, col);
_locked[x] = true;
}
}
} else
{
for (int x = i2; x < _led_count; x++)
{
if (x >= 0 && x < _led_count)
{
Adafruit_NeoPixel::setPixelColor(x, col);
_locked[x] = true;
}
}
for (int x = 0; x <= i; x++)
{
if (x >= 0 && x < _led_count)
{
Adafruit_NeoPixel::setPixelColor(x, col);
_locked[x] = true;
}
}
}
//Adafruit_NeoPixel::show();
}
void WS2812FX::lock(int i)
{
if (i >= 0 && i < _led_count)
_locked[i] = true;
}
void WS2812FX::lockRange(int i, int i2)
{
for (int x = i; x < i2; x++)
{
if (x >= 0 && x < _led_count)
Adafruit_NeoPixel::setPixelColor(x, _color);
_locked[x] = true;
}
Adafruit_NeoPixel::show();
}
void WS2812FX::lockAll()
{
for (int x = 0; x < _led_count; x++)
_locked[x] = true;
}
void WS2812FX::unlock(int i)
{
if (i >= 0 && i < _led_count)
_locked[i] = false;
}
void WS2812FX::unlockRange(int i, int i2)
{
for (int x = i; x < i2; x++)
{
if (x >= 0 && x < _led_count)
_locked[x] = false;
}
}
void WS2812FX::unlockAll()
{
for (int x = 0; x < _led_count; x++)
_locked[x] = false;
}

View File

@ -50,7 +50,7 @@
#define BRIGHTNESS_MIN 0
#define BRIGHTNESS_MAX 255
#define MODE_COUNT 48
#define MODE_COUNT 47
#define FX_MODE_STATIC 0
#define FX_MODE_BLINK 1
@ -99,7 +99,6 @@
#define FX_MODE_MERRY_CHRISTMAS 44
#define FX_MODE_FIRE_FLICKER 45
#define FX_MODE_FIRE_FLICKER_SOFT 46
#define FX_MODE_INDIVIDUAL_CONTROL 47
class WS2812FX : public Adafruit_NeoPixel {
@ -155,7 +154,6 @@ class WS2812FX : public Adafruit_NeoPixel {
_mode[FX_MODE_MERRY_CHRISTMAS] = &WS2812FX::mode_merry_christmas;
_mode[FX_MODE_FIRE_FLICKER] = &WS2812FX::mode_fire_flicker;
_mode[FX_MODE_FIRE_FLICKER_SOFT] = &WS2812FX::mode_fire_flicker_soft;
_mode[FX_MODE_INDIVIDUAL_CONTROL] = &WS2812FX::mode_individual_control;
_name[FX_MODE_STATIC] = "Static";
_name[FX_MODE_BLINK] = "Blink";
@ -204,7 +202,6 @@ class WS2812FX : public Adafruit_NeoPixel {
_name[FX_MODE_MERRY_CHRISTMAS] = "Merry Christmas";
_name[FX_MODE_FIRE_FLICKER] = "Fire Flicker";
_name[FX_MODE_FIRE_FLICKER_SOFT] = "Fire Flicker (soft)";
_name[FX_MODE_INDIVIDUAL_CONTROL] = "Individual Pixel Control";
_mode_index = DEFAULT_MODE;
_speed = DEFAULT_SPEED;
@ -217,6 +214,7 @@ class WS2812FX : public Adafruit_NeoPixel {
_mode_color = DEFAULT_COLOR;
_counter_mode_call = 0;
_counter_mode_step = 0;
_locked = new boolean[n];
}
void
@ -234,10 +232,19 @@ class WS2812FX : public Adafruit_NeoPixel {
increaseBrightness(uint8_t s),
decreaseBrightness(uint8_t s),
setIndividual(int i),
setRange(int i, int i2);
setIndividual(int i, uint32_t col),
setRange(int i, int i2),
setRange(int i, int i2, uint32_t col),
lock(int i),
lockRange(int i, int i2),
lockAll(void),
unlock(int i),
unlockRange(int i, int i2),
unlockAll(void);
boolean
isRunning(void);
isRunning(void),
isLocked(int i);
uint8_t
getMode(void),
@ -255,6 +262,7 @@ class WS2812FX : public Adafruit_NeoPixel {
void
strip_off(void),
strip_off_respectLock(void),
mode_static(void),
mode_blink(void),
mode_color_wipe(void),
@ -308,6 +316,9 @@ class WS2812FX : public Adafruit_NeoPixel {
boolean
_running;
boolean*
_locked;
uint8_t
get_random_wheel_index(uint8_t),
_mode_index,

View File

@ -1,3 +1,7 @@
/*
* Main sketch
*/
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
@ -18,12 +22,12 @@
* @author Christian Schwinne
*/
//Hardware-settings (only changeble via code)
uint8_t led_amount = 9;
uint8_t led_amount = 84;
uint8_t buttonPin = 0; //needs pull-up
TimeChangeRule CEST = {"CEST", Last, Sun, Mar, 2, 120}; //Central European Summer Time
TimeChangeRule CET = {"CET ", Last, Sun, Oct, 3, 60}; //Central European Standard Time
Timezone CE(CEST, CET);
Timezone TZ(CEST, CET);
TimeChangeRule *tcr; //pointer to the time change rule, use to get the TZ abbrev
time_t local;
@ -62,6 +66,10 @@ boolean ntpEnabled = true;
const char* ntpServerName = "time.nist.gov";
long ntpRetryMs = 20000;
long ntpResyncMs = 72000000;
int overlayMin = 0, overlayMax = 79;
int analogClock12pixel = 25;
boolean analogClockSecondsTrail = false;
boolean analogClock5MinuteMarks = true;
double transitionResolution = 0.011;
@ -94,6 +102,9 @@ boolean ntpConnected = false;
boolean ntpSyncNeeded = true;
boolean ntpPacketSent = false;
long ntpPacketSentTime, ntpSyncTime;
uint8_t overlayCurrent = 2;
long overlayRefreshMs = 200;
long overlayRefreshedTime;
ESP8266WebServer server(80);
ESP8266HTTPUpdateServer httpUpdater;
@ -137,6 +148,7 @@ void loop() {
handleNightlight();
handleButton();
handleNetworkTime();
handleOverlays();
strip.service();
}

View File

@ -1,3 +1,7 @@
/*
* Methods to handle saving and loading to non-volatile memory
*/
void clearEEPROM()
{
for (int i = 0; i < 1024; i++)

View File

@ -1,3 +1,7 @@
/*
* Sending XML status files to client
*/
void XML_response()
{
String resp;

View File

@ -1,3 +1,7 @@
/*
* Receives client input
*/
void handleSettingsSet()
{
if (server.hasArg("CSSID")) clientssid = server.arg("CSSID");
@ -224,7 +228,7 @@ boolean handleSet(String req)
effectUpdated = true;
}
}
pos = req.indexOf("XS=");
pos = req.indexOf("SX=");
if (pos > 0) {
if (effectSpeed != req.substring(pos + 3).toInt())
{
@ -235,8 +239,6 @@ boolean handleSet(String req)
}
pos = req.indexOf("I=");
if (pos > 0){
if (strip.getMode() != 47) strip.setMode(47);
effectCurrent = 47;
int index = req.substring(pos + 2).toInt();
pos = req.indexOf("I2=");
if (pos > 0){

View File

@ -1,3 +1,7 @@
/*
* Utility for SPIFFS filesystem
*/
String formatBytes(size_t bytes){
if (bytes < 1024){
return String(bytes)+"B";

View File

@ -1,3 +1,7 @@
/*
* Setup code
*/
void wledInit()
{
Serial.begin(115200);

View File

@ -1,2 +1,6 @@
/*
* foo
*/
String readFromFS(String filename){return "NI";};
void writeToFS(String filename, String file) {};

View File

@ -1,3 +1,7 @@
/*
* UDP notifier
*/
void notify(uint8_t callMode)
{
if (!udpConnected || !notifyMaster) return;
@ -40,10 +44,16 @@ void handleNotifications()
col[0] = udpIn[3];
col[1] = udpIn[4];
col[2] = udpIn[5];
effectCurrent = udpIn[8];
strip.setMode(effectCurrent);
effectSpeed = udpIn[9];
strip.setSpeed(effectSpeed);
if (udpIn[8] != effectCurrent)
{
effectCurrent = udpIn[8];
strip.setMode(effectCurrent);
}
if (udpIn[9] != effectSpeed)
{
effectSpeed = udpIn[9];
strip.setSpeed(effectSpeed);
}
nightlightActive = udpIn[6];
if (!udpIn[6])
{

View File

@ -1,3 +1,7 @@
/*
* LED methods
*/
void setAllLeds() {
double d = bri_t*bri_n;
int val = d/100;

View File

@ -1,3 +1,7 @@
/*
* Physical IO
*/
void handleButton()
{
if (buttonEnabled)

View File

@ -1,3 +1,7 @@
/*
* Acquires time from NTP server
*/
void handleNetworkTime()
{
if (ntpEnabled && ntpConnected)
@ -53,6 +57,7 @@ bool getNtpTime()
void sendNTPpacket()
{
while (ntpUdp.parsePacket()>0);
Serial.println("Sending NTP packet");
memset(ntpBuffer, 0, 48);
ntpBuffer[0] = 0b11100011; // LI, Version, Mode
@ -70,7 +75,7 @@ void sendNTPpacket()
String getTimeString()
{
local = CE.toLocal(now(), &tcr);
local = TZ.toLocal(now(), &tcr);
String ret = monthStr(month(local));
ret = ret + " ";
ret = ret + day(local);

50
wled00/wled11_ol.ino Normal file
View File

@ -0,0 +1,50 @@
void handleOverlays()
{
//properties: range, (color)
//0 no overlay
//1 solid color
//2 analog clock
//3 digital nixie-style clock one digit
if (millis() - overlayRefreshedTime > overlayRefreshMs)
{
overlayRefreshedTime = millis();
switch (overlayCurrent)
{
case 2: //2 analog clock
int overlaySize = overlayMax - overlayMin +1;
strip.unlockAll();
local = TZ.toLocal(now(), &tcr);
double hourP = ((double)(hour(local)%12))/12;
double minuteP = ((double)minute(local))/60;
hourP = hourP + minuteP/12;
double secondP = ((double)second(local))/60;
int hourPixel = floor(overlayMin + analogClock12pixel + overlaySize*hourP);
if (hourPixel > overlayMax) hourPixel = hourPixel - overlayMax;
int minutePixel = floor(overlayMin + analogClock12pixel + overlaySize*minuteP);
if (minutePixel > overlayMax) minutePixel = minutePixel - overlayMax;
int secondPixel = floor(overlayMin + analogClock12pixel + overlaySize*secondP);
if (secondPixel > overlayMax) secondPixel = secondPixel - overlayMax;
if (analogClock5MinuteMarks)
{
int pix;
for (int i = 0; i <= 12; i++)
{
pix = overlayMin + analogClock12pixel + (overlaySize/12)*i;
if (pix > overlayMax) pix = pix - overlayMax;
strip.setIndividual(pix, 0xAAAAAA);
}
}
if (analogClockSecondsTrail)
{
strip.setRange(analogClock12pixel, secondPixel, 0x0000FF);
} else
{
strip.setIndividual(secondPixel, 0x0000FF);
}
strip.setIndividual(minutePixel, 0x00FF00);
strip.setIndividual(hourPixel, 0xFF0000);
overlayRefreshMs = 998;
}
}
}