WS2812b Color Order changeable in settings
Meteor effect can now use palettes
This commit is contained in:
parent
c4c2494dd1
commit
a20d577f6c
@ -12,9 +12,6 @@
|
||||
#define AUXPIN 15 //unused auxiliary output pin
|
||||
|
||||
|
||||
//uncomment this if red and green are swapped
|
||||
//#define SWAPRG
|
||||
|
||||
|
||||
//automatically uses the right driver method for each platform
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
@ -36,14 +33,11 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//handle swapping Red and Green automatically
|
||||
#ifdef SWAPRG
|
||||
#define PIXELFEATURE3 NeoRgbFeature
|
||||
#define PIXELFEATURE4 NeoRgbwFeature
|
||||
#else
|
||||
#define PIXELFEATURE3 NeoGrbFeature
|
||||
#define PIXELFEATURE4 NeoGrbwFeature
|
||||
#endif
|
||||
|
||||
//you can now change the color order in the web settings
|
||||
#define PIXELFEATURE3 NeoGrbFeature
|
||||
#define PIXELFEATURE4 NeoGrbwFeature
|
||||
|
||||
|
||||
#include <NeoPixelBrightnessBus.h>
|
||||
|
||||
|
@ -93,7 +93,7 @@ void WS2812FX::clear()
|
||||
|
||||
bool WS2812FX::modeUsesLock(uint8_t m)
|
||||
{
|
||||
if (m == FX_MODE_FIRE_2012 || m == FX_MODE_COLORTWINKLE) return true;
|
||||
if (m == FX_MODE_FIRE_2012 || m == FX_MODE_COLORTWINKLE || m == FX_MODE_METEOR) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -241,6 +241,7 @@ void WS2812FX::setSecondaryColor(uint32_t c) {
|
||||
}
|
||||
|
||||
void WS2812FX::setBrightness(uint8_t b) {
|
||||
if (_brightness == b) return;
|
||||
_brightness = b;
|
||||
bus->SetBrightness(_brightness);
|
||||
show();
|
||||
@ -294,7 +295,15 @@ uint32_t WS2812FX::getPixelColor(uint16_t i)
|
||||
}
|
||||
}
|
||||
RgbwColor lColor = bus->GetPixelColorRgbw(i);
|
||||
return lColor.W*16777216 + lColor.R*65536 + lColor.G*256 + lColor.B;
|
||||
byte r = lColor.R, g = lColor.G, b = lColor.B;
|
||||
switch (colorOrder)
|
||||
{
|
||||
case 0: break; //0 = Grb
|
||||
case 1: r = lColor.G; g = lColor.R; break; //1 = Rgb, common for WS2811
|
||||
case 2: g = lColor.B; b = lColor.G; break; //2 = Brg
|
||||
case 3: r = lColor.B; g = lColor.R; b = lColor.G; //3 = Rbg
|
||||
}
|
||||
return ( (lColor.W << 24) | (r << 16) | (g << 8) | (b) );
|
||||
}
|
||||
|
||||
WS2812FX::Segment WS2812FX::getSegment(void) {
|
||||
@ -2158,7 +2167,10 @@ void WS2812FX::handle_palette(void)
|
||||
bool singleSegmentMode = (_segment_index == _segment_index_palette_last);
|
||||
_segment_index_palette_last = _segment_index;
|
||||
|
||||
switch (SEGMENT.palette)
|
||||
byte paletteIndex = SEGMENT.palette;
|
||||
if (SEGMENT.mode == FX_MODE_METEOR && SEGMENT.palette == 0) paletteIndex = 4;
|
||||
|
||||
switch (paletteIndex)
|
||||
{
|
||||
case 0: {//default palette. Differs depending on effect
|
||||
switch (SEGMENT.mode)
|
||||
@ -2566,30 +2578,44 @@ uint16_t WS2812FX::mode_lake() {
|
||||
return 33;
|
||||
}
|
||||
|
||||
// meteor effect
|
||||
// send a meteor from begining to to the end of the strip with a trail that randomly decay.
|
||||
// adapted from https://www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/#LEDStripEffectMeteorRain
|
||||
|
||||
// meteor effect
|
||||
// send a meteor from begining to to the end of the strip with a trail that randomly decays.
|
||||
// adapted from https://www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/#LEDStripEffectMeteorRain
|
||||
uint16_t WS2812FX::mode_meteor() {
|
||||
byte meteorSize=1+(256-SEGMENT.intensity)/16;
|
||||
uint32_t led_offset = SEGMENT_RUNTIME.counter_mode_step;
|
||||
uint16_t i = SEGMENT.start + led_offset;
|
||||
byte meteorTrailDecay=SEGMENT.intensity;
|
||||
byte meteorSize= 1+ SEGMENT_LENGTH / 10;
|
||||
uint16_t in = SEGMENT.start + SEGMENT_RUNTIME.counter_mode_step;
|
||||
|
||||
byte decayProb = 255 - SEGMENT.intensity;
|
||||
|
||||
// fade all leds to colors[1] in LEDs one step
|
||||
for (uint16_t i = SEGMENT.start; i <= SEGMENT.stop; i++) {
|
||||
if (random(10)>5) {
|
||||
setPixelColor(i,color_blend(getPixelColor(i),SEGMENT.colors[1],meteorTrailDecay));
|
||||
if (random8() <= decayProb)
|
||||
{
|
||||
byte meteorTrailDecay = 128 + random8(127);
|
||||
_locked[i] = scale8(_locked[i], meteorTrailDecay);
|
||||
setPixelColor(i, color_from_palette(_locked[i], false, true, 255));
|
||||
}
|
||||
}
|
||||
|
||||
// draw meteor
|
||||
for(int j = 0; j < meteorSize; j++) {
|
||||
if( ( SEGMENT.start + j < SEGMENT.stop) ) {
|
||||
setPixelColor(i+j, SEGMENT.colors[0]);
|
||||
uint16_t index = in + j;
|
||||
if(in + j > SEGMENT.stop) {
|
||||
index = SEGMENT.start + (in + j - SEGMENT.stop) -1;
|
||||
}
|
||||
|
||||
_locked[index] = 240;
|
||||
setPixelColor(index, color_from_palette(_locked[index], false, true, 255));
|
||||
}
|
||||
|
||||
SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) % (SEGMENT_LENGTH);
|
||||
return SPEED_FORMULA_L;
|
||||
}
|
||||
|
||||
//smooth
|
||||
//front ramping (maybe from get color
|
||||
//50fps
|
||||
//fade each led by a certain range (even ramp possible for sparkling)
|
||||
//maybe dim to color[1] at end?
|
||||
//_locked 0-15 bg-last 15-240 last-first 240-255 first-bg
|
||||
|
@ -165,6 +165,8 @@
|
||||
#define FX_MODE_COLORTWINKLE 74
|
||||
#define FX_MODE_LAKE 75
|
||||
#define FX_MODE_METEOR 76
|
||||
#define FX_MODE_SMOOTH_METEOR 77
|
||||
#define FX_MODE_RAILROAD_X 78
|
||||
|
||||
|
||||
class WS2812FX {
|
||||
|
Binary file not shown.
@ -96,6 +96,13 @@ const char PAGE_settings_leds1[] PROGMEM = R"=====(
|
||||
<h2>LED setup</h2>
|
||||
LED count: <input name="LC" type="number" min="1" max="1200" required><br>
|
||||
LEDs are 4-channel type (RGBW): <input type="checkbox" name="EW"><br>
|
||||
Color order:
|
||||
<select name="CO">
|
||||
<option value="0">GRB</option>
|
||||
<option value="1">RGB</option>
|
||||
<option value="2">BRG</option>
|
||||
<option value="3">RBG</option>
|
||||
</select><br>
|
||||
<br>
|
||||
Apply preset <input name="BP" type="number" min="0" max="25" required> at boot (0 uses defaults)<br>
|
||||
Turn on after power up/reset: <input type="checkbox" name="BO"><br>
|
||||
|
@ -74,7 +74,7 @@
|
||||
|
||||
|
||||
//version code in format yymmddb (b = daily build)
|
||||
#define VERSION 1811241
|
||||
#define VERSION 1811253
|
||||
char versionString[] = "0.8.2-dev";
|
||||
|
||||
|
||||
|
@ -142,6 +142,7 @@ void saveSettingsToEEPROM()
|
||||
EEPROM.write(380, colSecS[2]);
|
||||
EEPROM.write(381, whiteSecS);
|
||||
EEPROM.write(382, strip.paletteBlend);
|
||||
EEPROM.write(383, strip.colorOrder);
|
||||
|
||||
EEPROM.write(385, irEnabled);
|
||||
|
||||
@ -452,6 +453,7 @@ void loadSettingsFromEEPROM(bool first)
|
||||
readStringFromEEPROM(2300, mqttServer, 32);
|
||||
readStringFromEEPROM(2333, mqttDeviceTopic, 32);
|
||||
readStringFromEEPROM(2366, mqttGroupTopic, 32);
|
||||
strip.colorOrder = EEPROM.read(383);
|
||||
}
|
||||
|
||||
receiveDirect = !EEPROM.read(2200);
|
||||
|
@ -196,6 +196,7 @@ void getSettingsJS(byte subPage)
|
||||
sappend('v',"CB",colS[2]);
|
||||
sappend('v',"CA",briS);
|
||||
sappend('c',"EW",useRGBW);
|
||||
sappend('i',"CO",strip.colorOrder);
|
||||
sappend('c',"AW",autoRGBtoRGBW);
|
||||
sappend('v',"CW",whiteS);
|
||||
sappend('v',"SR",colSecS[0]);
|
||||
|
@ -60,6 +60,7 @@ void handleSettingsSet(byte subPage)
|
||||
if (ledCount > 600) ledCount = 600;
|
||||
#endif
|
||||
useRGBW = server.hasArg("EW");
|
||||
strip.colorOrder = server.arg("CO").toInt();
|
||||
autoRGBtoRGBW = server.hasArg("AW");
|
||||
|
||||
//ignore settings and save current brightness, colors and fx as default
|
||||
|
Loading…
Reference in New Issue
Block a user