Added Colortwinkle effect 74

This commit is contained in:
cschwinne 2018-11-04 20:14:23 +01:00
parent 81c810eba4
commit 9904c10984
7 changed files with 94 additions and 55 deletions

View File

@ -40,7 +40,6 @@
#include "WS2812FX.h" #include "WS2812FX.h"
#include "FastLED.h"
#include "palettes.h" #include "palettes.h"
void WS2812FX::init(bool supportWhite, uint16_t countPixels, bool skipFirst) void WS2812FX::init(bool supportWhite, uint16_t countPixels, bool skipFirst)
@ -90,6 +89,12 @@ void WS2812FX::clear()
bus->ClearTo(RgbColor(0)); bus->ClearTo(RgbColor(0));
} }
bool WS2812FX::modeUsesLock(uint8_t m)
{
if (m == FX_MODE_FIRE_2012 || m == FX_MODE_COLORTWINKLE) return true;
return false;
}
void WS2812FX::setPixelColor(uint16_t n, uint32_t c) { void WS2812FX::setPixelColor(uint16_t n, uint32_t c) {
uint8_t w = (c >> 24) & 0xFF; uint8_t w = (c >> 24) & 0xFF;
uint8_t r = (c >> 16) & 0xFF; uint8_t r = (c >> 16) & 0xFF;
@ -100,7 +105,7 @@ void WS2812FX::setPixelColor(uint16_t n, uint32_t c) {
void WS2812FX::setPixelColor(uint16_t i, byte r, byte g, byte b, byte w) void WS2812FX::setPixelColor(uint16_t i, byte r, byte g, byte b, byte w)
{ {
if (_locked[i] && SEGMENT.mode != FX_MODE_FIRE_2012) return; if (_locked[i] && !modeUsesLock(SEGMENT.mode)) return;
if (_reverseMode) i = _length - 1 -i; if (_reverseMode) i = _length - 1 -i;
if (IS_REVERSE) i = SEGMENT.stop - (i - SEGMENT.start); //reverse just individual segment if (IS_REVERSE) i = SEGMENT.stop - (i - SEGMENT.start); //reverse just individual segment
if (!_cronixieMode) if (!_cronixieMode)
@ -177,7 +182,7 @@ void WS2812FX::trigger() {
void WS2812FX::setMode(uint8_t m) { void WS2812FX::setMode(uint8_t m) {
RESET_RUNTIME; RESET_RUNTIME;
bool ua = _segments[0].mode == FX_MODE_FIRE_2012 && m != FX_MODE_FIRE_2012; bool ua = modeUsesLock(_segments[0].mode) && !modeUsesLock(m);
_segments[0].mode = constrain(m, 0, MODE_COUNT - 1); _segments[0].mode = constrain(m, 0, MODE_COUNT - 1);
if (ua) unlockAll(); if (ua) unlockAll();
setBrightness(_brightness); setBrightness(_brightness);
@ -318,7 +323,7 @@ void WS2812FX::resetSegments() {
void WS2812FX::setIndividual(uint16_t i, uint32_t col) void WS2812FX::setIndividual(uint16_t i, uint32_t col)
{ {
if (SEGMENT.mode == FX_MODE_FIRE_2012) return; if (modeUsesLock(SEGMENT.mode)) return;
if (i >= 0 && i < _length) if (i >= 0 && i < _length)
{ {
_locked[i] = false; _locked[i] = false;
@ -340,13 +345,13 @@ void WS2812FX::setRange(uint16_t i, uint16_t i2, uint32_t col)
void WS2812FX::lock(uint16_t i) void WS2812FX::lock(uint16_t i)
{ {
if (SEGMENT.mode == FX_MODE_FIRE_2012) return; if (modeUsesLock(SEGMENT.mode)) return;
if (i >= 0 && i < _length) _locked[i] = true; if (i >= 0 && i < _length) _locked[i] = true;
} }
void WS2812FX::lockRange(uint16_t i, uint16_t i2) void WS2812FX::lockRange(uint16_t i, uint16_t i2)
{ {
if (SEGMENT.mode == FX_MODE_FIRE_2012) return; if (modeUsesLock(SEGMENT.mode)) return;
for (uint16_t x = i; x <= i2; x++) for (uint16_t x = i; x <= i2; x++)
{ {
if (i >= 0 && i < _length) _locked[i] = true; if (i >= 0 && i < _length) _locked[i] = true;
@ -355,13 +360,13 @@ void WS2812FX::lockRange(uint16_t i, uint16_t i2)
void WS2812FX::unlock(uint16_t i) void WS2812FX::unlock(uint16_t i)
{ {
if (SEGMENT.mode == FX_MODE_FIRE_2012) return; if (modeUsesLock(SEGMENT.mode)) return;
if (i >= 0 && i < _length) _locked[i] = false; if (i >= 0 && i < _length) _locked[i] = false;
} }
void WS2812FX::unlockRange(uint16_t i, uint16_t i2) void WS2812FX::unlockRange(uint16_t i, uint16_t i2)
{ {
if (SEGMENT.mode == FX_MODE_FIRE_2012) return; if (modeUsesLock(SEGMENT.mode)) return;
for (uint16_t x = i; x < i2; x++) for (uint16_t x = i; x < i2; x++)
{ {
if (x >= 0 && x < _length) _locked[x] = false; if (x >= 0 && x < _length) _locked[x] = false;
@ -377,7 +382,7 @@ void WS2812FX::setTransitionMode(bool t)
{ {
SEGMENT_RUNTIME.trans_act = (t) ? 1:2; SEGMENT_RUNTIME.trans_act = (t) ? 1:2;
if (!t) return; if (!t) return;
unsigned long waitMax = millis() + 20; //refresh after 20 seconds if transition enabled unsigned long waitMax = millis() + 20; //refresh after 20 ms if transition enabled
if (SEGMENT.mode == FX_MODE_STATIC && SEGMENT_RUNTIME.next_time > waitMax) SEGMENT_RUNTIME.next_time = waitMax; if (SEGMENT.mode == FX_MODE_STATIC && SEGMENT_RUNTIME.next_time > waitMax) SEGMENT_RUNTIME.next_time = waitMax;
} }
@ -2051,6 +2056,15 @@ uint16_t WS2812FX::mode_lightning(void)
} }
CRGB WS2812FX::fastled_from_col(uint32_t color)
{
CRGB fastled_col;
fastled_col.red = (color >> 16 & 0xFF);
fastled_col.green = (color >> 8 & 0xFF);
fastled_col.blue = (color & 0xFF);
return fastled_col;
}
// Pride2015 // Pride2015
// Animated, ever-changing rainbows. // Animated, ever-changing rainbows.
// by Mark Kriegsman: https://gist.github.com/kriegsman/964de772d64c502760e5 // by Mark Kriegsman: https://gist.github.com/kriegsman/964de772d64c502760e5
@ -2085,11 +2099,7 @@ uint16_t WS2812FX::mode_pride_2015(void)
bri8 += (255 - brightdepth); bri8 += (255 - brightdepth);
CRGB newcolor = CHSV( hue8, sat8, bri8); CRGB newcolor = CHSV( hue8, sat8, bri8);
fastled_col = fastled_from_col(getPixelColor(i));
uint32_t color = getPixelColor(i);
fastled_col.red = (color >> 16 & 0xFF);
fastled_col.green = (color >> 8 & 0xFF);
fastled_col.blue = (color & 0xFF);
nblend( fastled_col, newcolor, 64); nblend( fastled_col, newcolor, 64);
setPixelColor(i, fastled_col.red, fastled_col.green, fastled_col.blue); setPixelColor(i, fastled_col.red, fastled_col.green, fastled_col.blue);
@ -2107,10 +2117,7 @@ uint16_t WS2812FX::mode_juggle(void){
byte dothue = 0; byte dothue = 0;
for ( byte i = 0; i < 8; i++) { for ( byte i = 0; i < 8; i++) {
uint16_t index = SEGMENT.start + beatsin16(i + 7, 0, SEGMENT_LENGTH -1); uint16_t index = SEGMENT.start + beatsin16(i + 7, 0, SEGMENT_LENGTH -1);
uint32_t color = getPixelColor(index); fastled_col = fastled_from_col(getPixelColor(index));
fastled_col.red = (color >> 16 & 0xFF);
fastled_col.green = (color >> 8 & 0xFF);
fastled_col.blue = (color & 0xFF);
fastled_col |= CHSV(dothue, 220, 255); fastled_col |= CHSV(dothue, 220, 255);
setPixelColor(index, fastled_col.red, fastled_col.green, fastled_col.blue); setPixelColor(index, fastled_col.red, fastled_col.green, fastled_col.blue);
dothue += 32; dothue += 32;
@ -2161,17 +2168,11 @@ void WS2812FX::handle_palette(void)
_lastPaletteChange = millis(); _lastPaletteChange = millis();
} break;} } break;}
case 2: {//primary color only case 2: {//primary color only
CRGB prim; CRGB prim = fastled_from_col(SEGMENT.colors[0]);
prim.red = (SEGMENT.colors[0] >> 16 & 0xFF);
prim.green = (SEGMENT.colors[0] >> 8 & 0xFF);
prim.blue = (SEGMENT.colors[0] & 0xFF);
targetPalette = CRGBPalette16(prim); break;} targetPalette = CRGBPalette16(prim); break;}
case 3: {//based on primary case 3: {//based on primary
//considering performance implications //considering performance implications
CRGB prim; CRGB prim = fastled_from_col(SEGMENT.colors[0]);
prim.red = (SEGMENT.colors[0] >> 16 & 0xFF);
prim.green = (SEGMENT.colors[0] >> 8 & 0xFF);
prim.blue = (SEGMENT.colors[0] & 0xFF);
CHSV prim_hsv = rgb2hsv_approximate(prim); CHSV prim_hsv = rgb2hsv_approximate(prim);
targetPalette = CRGBPalette16( targetPalette = CRGBPalette16(
CHSV(prim_hsv.h, prim_hsv.s, prim_hsv.v), //color itself CHSV(prim_hsv.h, prim_hsv.s, prim_hsv.v), //color itself
@ -2180,24 +2181,12 @@ void WS2812FX::handle_palette(void)
CHSV(prim_hsv.h, prim_hsv.s, prim_hsv.v)); //color itself CHSV(prim_hsv.h, prim_hsv.s, prim_hsv.v)); //color itself
break;} break;}
case 4: {//primary + secondary case 4: {//primary + secondary
CRGB prim; CRGB prim = fastled_from_col(SEGMENT.colors[0]);
prim.red = (SEGMENT.colors[0] >> 16 & 0xFF); CRGB sec = fastled_from_col(SEGMENT.colors[1]);
prim.green = (SEGMENT.colors[0] >> 8 & 0xFF);
prim.blue = (SEGMENT.colors[0] & 0xFF);
CRGB sec;
sec.red = (SEGMENT.colors[1] >> 16 & 0xFF);
sec.green = (SEGMENT.colors[1] >> 8 & 0xFF);
sec.blue = (SEGMENT.colors[1] & 0xFF);
targetPalette = CRGBPalette16(sec,prim); break;} targetPalette = CRGBPalette16(sec,prim); break;}
case 5: {//based on primary + secondary case 5: {//based on primary + secondary
CRGB prim; CRGB prim = fastled_from_col(SEGMENT.colors[0]);
prim.red = (SEGMENT.colors[0] >> 16 & 0xFF); CRGB sec = fastled_from_col(SEGMENT.colors[1]);
prim.green = (SEGMENT.colors[0] >> 8 & 0xFF);
prim.blue = (SEGMENT.colors[0] & 0xFF);
CRGB sec;
sec.red = (SEGMENT.colors[1] >> 16 & 0xFF);
sec.green = (SEGMENT.colors[1] >> 8 & 0xFF);
sec.blue = (SEGMENT.colors[1] & 0xFF);
targetPalette = CRGBPalette16(sec,prim,CRGB::White); break;} targetPalette = CRGBPalette16(sec,prim,CRGB::White); break;}
case 6: //Party colors case 6: //Party colors
targetPalette = PartyColors_p; break; targetPalette = PartyColors_p; break;
@ -2359,11 +2348,7 @@ uint16_t WS2812FX::mode_colorwaves(void)
index = scale8( index, 240); index = scale8( index, 240);
CRGB newcolor = ColorFromPalette(currentPalette, index, bri8); CRGB newcolor = ColorFromPalette(currentPalette, index, bri8);
fastled_col = fastled_from_col(getPixelColor(i));
uint32_t color = getPixelColor(i);
fastled_col.red = (color >> 16 & 0xFF);
fastled_col.green = (color >> 8 & 0xFF);
fastled_col.blue = (color & 0xFF);
nblend(fastled_col, newcolor, 128); nblend(fastled_col, newcolor, 128);
setPixelColor(i, fastled_col.red, fastled_col.green, fastled_col.blue); setPixelColor(i, fastled_col.red, fastled_col.green, fastled_col.blue);
@ -2497,3 +2482,47 @@ uint16_t WS2812FX::mode_noise16_4(void)
} }
return 20; return 20;
} }
uint16_t WS2812FX::mode_colortwinkle()
{
CRGB fastled_col, prev;
fract8 fadeUpAmount = 8 + (SEGMENT.speed/4), fadeDownAmount = 5 + (SEGMENT.speed/7);
for( uint16_t i = SEGMENT.start; i <= SEGMENT.stop; i++) {
fastled_col = fastled_from_col(getPixelColor(i));
prev = fastled_col;
if(_locked[i]) {
CRGB incrementalColor = fastled_col;
incrementalColor.nscale8_video( fadeUpAmount);
fastled_col += incrementalColor;
if( fastled_col.red == 255 || fastled_col.green == 255 || fastled_col.blue == 255) {
_locked[i] = false;
}
setPixelColor(i, fastled_col.red, fastled_col.green, fastled_col.blue);
if (fastled_from_col(getPixelColor(i)) == prev) //fix "stuck" pixels
{
fastled_col += fastled_col;
setPixelColor(i, fastled_col.red, fastled_col.green, fastled_col.blue);
}
} else {
fastled_col.nscale8( 255 - fadeDownAmount);
setPixelColor(i, fastled_col.red, fastled_col.green, fastled_col.blue);
}
}
if( random8() <= SEGMENT.intensity ) {
for (uint8_t times = 0; times < 5; times++) //attempt to spawn a new pixel 5 times
{
int i = SEGMENT.start + random16(SEGMENT_LENGTH);
if(getPixelColor(i) == 0) {
fastled_col = ColorFromPalette( currentPalette, random8(), 64, NOBLEND);
_locked[i] = true;
setPixelColor(i, fastled_col.red, fastled_col.green, fastled_col.blue);
return 20; //only spawn 1 new pixel per frame
}
}
}
return 20;
}

View File

@ -40,6 +40,7 @@
#define WS2812FX_h #define WS2812FX_h
#include "NpbWrapper.h" #include "NpbWrapper.h"
#include "FastLED.h"
#define DEFAULT_BRIGHTNESS (uint8_t)50 #define DEFAULT_BRIGHTNESS (uint8_t)50
#define DEFAULT_MODE (uint8_t)0 #define DEFAULT_MODE (uint8_t)0
@ -82,7 +83,7 @@
#define REVERSE (uint8_t)0x80 #define REVERSE (uint8_t)0x80
#define IS_REVERSE ((SEGMENT.options & REVERSE) == REVERSE) #define IS_REVERSE ((SEGMENT.options & REVERSE) == REVERSE)
#define MODE_COUNT 74 #define MODE_COUNT 75
#define FX_MODE_STATIC 0 #define FX_MODE_STATIC 0
#define FX_MODE_BLINK 1 #define FX_MODE_BLINK 1
@ -159,6 +160,7 @@
#define FX_MODE_NOISE16_2 71 #define FX_MODE_NOISE16_2 71
#define FX_MODE_NOISE16_3 72 #define FX_MODE_NOISE16_3 72
#define FX_MODE_NOISE16_4 73 #define FX_MODE_NOISE16_4 73
#define FX_MODE_COLORTWINKLE 74
class WS2812FX { class WS2812FX {
typedef uint16_t (WS2812FX::*mode_ptr)(void); typedef uint16_t (WS2812FX::*mode_ptr)(void);
@ -261,6 +263,7 @@ class WS2812FX {
_mode[FX_MODE_NOISE16_2] = &WS2812FX::mode_noise16_2; _mode[FX_MODE_NOISE16_2] = &WS2812FX::mode_noise16_2;
_mode[FX_MODE_NOISE16_3] = &WS2812FX::mode_noise16_3; _mode[FX_MODE_NOISE16_3] = &WS2812FX::mode_noise16_3;
_mode[FX_MODE_NOISE16_4] = &WS2812FX::mode_noise16_4; _mode[FX_MODE_NOISE16_4] = &WS2812FX::mode_noise16_4;
_mode[FX_MODE_COLORTWINKLE] = &WS2812FX::mode_colortwinkle;
_brightness = DEFAULT_BRIGHTNESS; _brightness = DEFAULT_BRIGHTNESS;
_running = false; _running = false;
@ -434,16 +437,20 @@ class WS2812FX {
mode_noise16_2(void), mode_noise16_2(void),
mode_noise16_3(void), mode_noise16_3(void),
mode_noise16_4(void), mode_noise16_4(void),
mode_colortwinkle(void),
mode_lightning(void); mode_lightning(void);
private: private:
NeoPixelWrapper *bus; NeoPixelWrapper *bus;
CRGB fastled_from_col(uint32_t);
uint16_t _length; uint16_t _length;
uint16_t _rand16seed; uint16_t _rand16seed;
uint8_t _brightness; uint8_t _brightness;
void handle_palette(void); void handle_palette(void);
bool modeUsesLock(uint8_t);
double double
_cronixieSecMultiplier; _cronixieSecMultiplier;

View File

@ -192,10 +192,10 @@
function SwFX(s) function SwFX(s)
{ {
var n=Cf.TX.selectedIndex+s; var n=Cf.TX.selectedIndex+s;
if (n==-1||n==74) return; if (n==-1||n==75) return;
Cf.TX.selectedIndex =n; Cf.TX.selectedIndex =n;
if (n < 0) Cf.TX.selectedIndex = 0; if (n < 0) Cf.TX.selectedIndex = 0;
if (n > 73) Cf.TX.selectedIndex = 65; if (n > 74) Cf.TX.selectedIndex = 65;
GX(); GX();
} }
function TgHSB() function TgHSB()
@ -660,6 +660,7 @@
<option value="71">Noise 16 2 (71)</option> <option value="71">Noise 16 2 (71)</option>
<option value="72">Noise 16 3 (72)</option> <option value="72">Noise 16 3 (72)</option>
<option value="73">Noise 16 4 (73)</option> <option value="73">Noise 16 4 (73)</option>
<option value="74">Colortwinkle (74)</option>
</select><br><br> </select><br><br>
Set secondary color to Set secondary color to
<button type="button" onclick="CS(0)">White</button> <button type="button" onclick="CS(0)">White</button>

View File

@ -432,7 +432,8 @@
<li onclick="X(70)">Noise 16 1</li> <li onclick="X(70)">Noise 16 1</li>
<li onclick="X(71)">Noise 16 2</li> <li onclick="X(71)">Noise 16 2</li>
<li onclick="X(72)">Noise 16 3</li> <li onclick="X(72)">Noise 16 3</li>
<li onclick="X(73)">Noise 16 4</li>&nbsp; <li onclick="X(73)">Noise 16 4</li>
<li onclick="X(74)">Colortwinkle</li>&nbsp;
<li><a href="#">Go to top</a></li>&nbsp; <li><a href="#">Go to top</a></li>&nbsp;
<p style="margin-left:-37px">FastLED Palette (Effects 56-73)</p> <p style="margin-left:-37px">FastLED Palette (Effects 56-73)</p>
<li onclick="P(0)">Default</li> <li onclick="P(0)">Default</li>

File diff suppressed because one or more lines are too long

View File

@ -63,7 +63,7 @@
//version code in format yymmddb (b = daily build) //version code in format yymmddb (b = daily build)
#define VERSION 1811012 #define VERSION 1811041
char versionString[] = "0.8.1"; char versionString[] = "0.8.1";

View File

@ -206,6 +206,7 @@ void handleNotifications()
if (udpIn[1] == 0) if (udpIn[1] == 0)
{ {
realtimeActive = false; realtimeActive = false;
return;
} else { } else {
arlsLock(udpIn[1]*1000); arlsLock(udpIn[1]*1000);
} }