Skip to content

Commit

Permalink
Improved fade modes
Browse files Browse the repository at this point in the history
  • Loading branch information
Aircoookie committed Oct 3, 2019
1 parent 1dccc8d commit 846a1d0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 43 deletions.
61 changes: 20 additions & 41 deletions wled00/WS2812FX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ 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.
// * to new random colors. NOTE: Problematic for revamp. Consider using data array?
*/
uint16_t WS2812FX::mode_dynamic(void) {
if(SEGMENT.intensity > 127 || SEGENV.call == 0) {
Expand All @@ -246,60 +246,39 @@ uint16_t WS2812FX::mode_dynamic(void) {


/*
* Does the "standby-breathing" of well known i-Devices. Fixed Speed.
* Use mode "fade" if you like to have something similar with a different speed.
* Does the "standby-breathing" of well known i-Devices.
*/
uint16_t WS2812FX::mode_breath(void) {
int lum = SEGENV.step;
if(lum > 255) lum = 511 - lum; // lum = 15 -> 255 -> 15

uint16_t delay;
if(lum == 15) delay = 465; // 970 pause before each breath
else if(lum <= 25) delay = 19; // 19
else if(lum <= 50) delay = 18; // 18
else if(lum <= 75) delay = 14; // 14
else if(lum <= 100) delay = 10; // 10
else if(lum <= 125) delay = 7; // 7
else if(lum <= 150) delay = 5; // 5
else delay = 4; // 4

if (SEGMENT.palette == 0)
{
uint32_t color = SEGCOLOR(0);
uint8_t w = ((color >> 24 & 0xFF) * lum) >> 8;
uint8_t r = ((color >> 16 & 0xFF) * lum) >> 8;
uint8_t g = ((color >> 8 & 0xFF) * lum) >> 8;
uint8_t b = ((color & 0xFF) * lum) >> 8;
for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) {
setPixelColor(i, r, g, b, w);
}
} else
{
for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) {
setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 0, lum));
}
uint16_t var = 0;
uint16_t counter = (now * ((SEGMENT.speed >> 3) +10)) & 0xFFFF;
counter = (counter >> 2) + (counter >> 4); //0-16384 + 0-2048
if (counter < 16384) {
if (counter > 8192) counter = 8192 - (counter - 8192);
var = sin16(counter) / 103; //close to parabolic in range 0-8192, max val. 23170
}

uint8_t lum = 30 + var;
for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) {
setPixelColor(i, color_blend(SEGCOLOR(1), color_from_palette(i, true, PALETTE_SOLID_WRAP, 0), lum));
}

SEGENV.step += 2;
if(SEGENV.step > (512-15)) SEGENV.step = 15;
return delay * (((256 - SEGMENT.speed)/64) +1);
return FRAMETIME;
}


/*
* Fades the LEDs between two colors
*/
uint16_t WS2812FX::mode_fade(void) {
int lum = SEGENV.step;
if(lum > 255) lum = 511 - lum; // lum = 0 -> 255 -> 0

uint16_t counter = (now * ((SEGMENT.speed >> 3) +10)) & 0xFFFF;
if (counter > 32767) counter = 32768 - (counter - 32768);
uint8_t lum = counter >> 7;

for(uint16_t i=SEGMENT.start; i < SEGMENT.stop; i++) {
setPixelColor(i, color_blend(color_from_palette(i, true, PALETTE_SOLID_WRAP, 0), SEGCOLOR(1), lum));
setPixelColor(i, color_blend(SEGCOLOR(1), color_from_palette(i, true, PALETTE_SOLID_WRAP, 0), lum));
}

SEGENV.step += 4;
if(SEGENV.step > 511) SEGENV.step = 0;
return 5 + ((15 * (uint32_t)(255 - SEGMENT.speed)) / 255);
return FRAMETIME;
}


Expand Down
2 changes: 1 addition & 1 deletion wled00/WS2812FX.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#define max(a,b) ((a)>(b)?(a):(b))

/* Not used in all effects yet */
#define WLED_FPS 50
#define WLED_FPS 42
#define FRAMETIME 1000/WLED_FPS

/* each segment uses 37 bytes of SRAM memory, so if you're application fails because of
Expand Down
2 changes: 1 addition & 1 deletion 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 1910032
#define VERSION 1910033
char versionString[] = "0.8.5";


Expand Down

0 comments on commit 846a1d0

Please sign in to comment.