Skip to content

Commit

Permalink
Improved rainbow effects
Browse files Browse the repository at this point in the history
  • Loading branch information
Aircoookie committed Oct 4, 2019
1 parent 273c646 commit f30ffb4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

## Welcome to my project WLED!

A fast and feature-rich implementation of an ESP8266/ESP32 webserver to control NeoPixel (WS2812B) LEDs!
A fast and feature-rich implementation of an ESP8266/ESP32 webserver to control NeoPixel (WS2812B, WS2811, SK6812, APA102) LEDs!

### Features:
- WS2812FX library integrated for 80 special effects
Expand Down
44 changes: 30 additions & 14 deletions wled00/WS2812FX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ uint16_t WS2812FX::mode_static(void) {
* Blink/strobe function
* Alternate between color1 and color2
* if(strobe == true) then create a strobe effect
* NOTE: Maybe re-rework without timer
*/
uint16_t WS2812FX::blink(uint32_t color1, uint32_t color2, bool strobe, bool do_palette) {
uint16_t stateTime = SEGENV.aux1;
Expand Down Expand Up @@ -232,16 +233,27 @@ uint16_t WS2812FX::mode_random_color(void) {

/*
* Lights every LED in a random color. Changes all LED at the same time
// * to new random colors. NOTE: Problematic for revamp. Consider using data array?
// * to new random colors.
*/
uint16_t WS2812FX::mode_dynamic(void) {
if(SEGMENT.intensity > 127 || SEGENV.call == 0) {
if(SEGENV.call == 0) {
for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) _locked[i] = random8();
}

uint32_t cycleTime = 50 + (255 - SEGMENT.speed)*15;
uint32_t it = now / cycleTime;
if (it != SEGENV.step) //new color
{
for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) {
setPixelColor(i, color_wheel(random8()));
if (random8() <= SEGMENT.intensity) _locked[i] = random8();
}
SEGENV.step = it;
}
setPixelColor(SEGMENT.start + random16(SEGLEN), color_wheel(random8()));
return 50 + (15 * (uint32_t)(255 - SEGMENT.speed));

for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) {
setPixelColor(i, color_wheel(_locked[i]));
}
return FRAMETIME;
}


Expand Down Expand Up @@ -309,7 +321,7 @@ uint16_t WS2812FX::scan(bool dual)
}


//TODO add intensity (more than 1 pixel lit)
//NOTE: add intensity (more than 1 pixel lit)
/*
* Runs a single pixel back and forth.
*/
Expand All @@ -330,25 +342,29 @@ uint16_t WS2812FX::mode_dual_scan(void) {
* Cycles all LEDs at once through a rainbow.
*/
uint16_t WS2812FX::mode_rainbow(void) {
uint32_t color = color_wheel(SEGENV.step);
fill(color);
uint16_t counter = (now * ((SEGMENT.speed >> 3) +2)) & 0xFFFF;
counter = counter >> 8;

SEGENV.step = (SEGENV.step + 1) & 0xFF;
return 1 + (((uint32_t)(255 - SEGMENT.speed)) / 5);
fill(color_wheel(counter));

return FRAMETIME;
}


/*
* Cycles a rainbow over the entire string of LEDs.
*/
uint16_t WS2812FX::mode_rainbow_cycle(void) {
uint16_t counter = (now * ((SEGMENT.speed >> 3) +2)) & 0xFFFF;
counter = counter >> 8;

for(uint16_t i=0; i < SEGLEN; i++) {
uint32_t color = color_wheel(((i * 256 / ((uint16_t)(SEGLEN*(float)(SEGMENT.intensity/128.0))+1)) + SEGENV.step) & 0xFF);
setPixelColor(SEGMENT.start + i, color);
//intensity/29 = 0 (1/16) 1 (1/8) 2 (1/4) 3 (1/2) 4 (1) 5 (2) 6 (4) 7 (8) 8 (16)
uint8_t index = (i * (16 << (SEGMENT.intensity /29)) / SEGLEN) + counter;
setPixelColor(SEGMENT.start + i, color_wheel(index));
}

SEGENV.step = (SEGENV.step + 1) & 0xFF;
return 1 + (((uint32_t)(255 - SEGMENT.speed)) / 5);
return FRAMETIME;
}


Expand Down
2 changes: 1 addition & 1 deletion wled00/WS2812FX_fcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ bool WS2812FX::modeUsesLock(uint8_t m)
{
if (m == FX_MODE_FIRE_2012 || m == FX_MODE_COLORTWINKLE ||
m == FX_MODE_METEOR || m == FX_MODE_METEOR_SMOOTH ||
m == FX_MODE_RIPPLE) return true;
m == FX_MODE_RIPPLE || m == FX_MODE_DYNAMIC ) return true;
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions wled00/wled00.ino
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@


//version code in format yymmddb (b = daily build)
#define VERSION 1910033
#define VERSION 1910042
char versionString[] = "0.8.5";


Expand Down Expand Up @@ -160,7 +160,7 @@ byte briMultiplier = 100; //% of brightness to set (to limit


//User Interface CONFIG
char serverDescription[33] = "WLED Light"; //Name of module
char serverDescription[33] = "WLED"; //Name of module
byte currentTheme = 7; //UI theme index for settings and classic UI
byte uiConfiguration = 0; //0: automatic (depends on user-agent) 1: classic UI 2: mobile UI
bool useHSB = true; //classic UI: use HSB sliders instead of RGB by default
Expand Down

0 comments on commit f30ffb4

Please sign in to comment.