Browse Source

add quadcolor chase effect

master
parent
commit
573db2434c
  1. 3
      Inc/ws2812b_fx.h
  2. 44
      Src/ws2812b_fx.c

3
Inc/ws2812b_fx.h

@ -23,7 +23,7 @@
#define SPEED_MIN (10) #define SPEED_MIN (10)
#define DEFAULT_SPEED (150) #define DEFAULT_SPEED (150)
#define SPEED_MAX (65535) #define SPEED_MAX (65535)
#define MODE_COUNT (58) #define MODE_COUNT (59)
#define DEFAULT_MODE (0) #define DEFAULT_MODE (0)
#define FADE_RATE (2) #define FADE_RATE (2)
/* some common colors */ /* some common colors */
@ -102,6 +102,7 @@ typedef enum {
FX_MODE_HALLOWEEN, FX_MODE_HALLOWEEN,
FX_MODE_BICOLOR_CHASE, FX_MODE_BICOLOR_CHASE,
FX_MODE_TRICOLOR_CHASE, FX_MODE_TRICOLOR_CHASE,
FX_MODE_QUADCOLOR_CHASE,
FX_MODE_ICU FX_MODE_ICU
} fx_mode; } fx_mode;

44
Src/ws2812b_fx.c

@ -157,6 +157,7 @@ mode_circus_combustus(void),
mode_halloween(void), mode_halloween(void),
mode_bicolor_chase(void), mode_bicolor_chase(void),
mode_tricolor_chase(void), mode_tricolor_chase(void),
mode_quadcolor_chase(void),
mode_icu(void) mode_icu(void)
; ;
@ -219,6 +220,7 @@ void (*mMode[MODE_COUNT])(void) =
mode_halloween, mode_halloween,
mode_bicolor_chase, mode_bicolor_chase,
mode_tricolor_chase, mode_tricolor_chase,
mode_quadcolor_chase,
mode_icu mode_icu
}; };
@ -1948,6 +1950,48 @@ void mode_tricolor_chase(void)
} }
/*
* Quadcolor chase function
*/
void quadcolor_chase(uint32_t color1, uint32_t color2, uint32_t color3, uint32_t color4)
{
uint16_t index = Ws28b12b_Segments[mActualSegment].CounterModeStep % 8;
uint16_t i;
uint32_t color;
for(i = 0; i < SEGMENT_LENGTH; i++, index++)
{
index %= 8;
color = color1;
if(index < 2) color = color2;
else if(index < 4) color = color3;
else if(index < 6) color = color4;
if(IS_REVERSE) {
ws2812_set_led_color_val(Ws28b12b_Segments[mActualSegment].IdStart + i, color);
} else {
ws2812_set_led_color_val(Ws28b12b_Segments[mActualSegment].IdStop - i, color);
}
}
Ws28b12b_Segments[mActualSegment].CounterModeStep++;
Ws28b12b_Segments[mActualSegment].ModeDelay = Ws28b12b_Segments[mActualSegment].Speed;
}
/*
* Quadcolor chase mode
*/
void mode_quadcolor_chase(void)
{
return quadcolor_chase(Ws28b12b_Segments[mActualSegment].ModeColor[0],
Ws28b12b_Segments[mActualSegment].ModeColor[1],
Ws28b12b_Segments[mActualSegment].ModeColor[2],
Ws28b12b_Segments[mActualSegment].ModeColor[3]);
}
/* /*
* Alternating white/red/black pixels running. * Alternating white/red/black pixels running.
*/ */

Loading…
Cancel
Save