WS2812B RGB - Fade Color
digital32
Posts: 11
I'm trying to fade from one color to another with a WS2812B RGB strip.
Working in the Simple IDE compiler so if possible I need it in C Code.
I can turn the RGBs on/off/set the colors... Now I want to fade from one color to another.
Anyone got some C code to smoothly fade from one color to another?
Looking for a procedure like this:
void Color_Fade(long _Start_Color, long _End_Color, int speedMS)
Here is example declarations for the color that I found in the Elev-8 flight controller.
// WS2812B RGB LED Module Variable Definitions
const int Extra_LED_Module_Count = 8; // Extra WS2812B RGB LED Module Count (Do not count the onboard WS2812B Module)
const int LED_COUNT = Extra_LED_Module_Count + 1; // + Onboard WS2812B
static long LEDValue[LED_COUNT]; // LED Outputs (Copied to the LEDs by the Sensors cog)
static long LEDModeColor; // Used to Set the LED Mode Color
const int FC_LED_Module = 0; // Flight Controller WS2812B RBG LED Module Index
//LED Brightness values - AND with color values to dim them
const int LED_Full = 0xffffff;
const int LED_Half = 0x7f7f7f;
const int LED_Quarter = 0x3f3f3f;
const int LED_Eighth = 0x1f1f1f;
const int LED_Dim = 0x0f0f0f;
//LED Color values
const int LED_Off = 0x000000;
const int LED_Red = 0x00FF00;
const int LED_Green = 0xFF0000;
const int LED_Blue = 0x0000FF;
const int LED_White = 0xFFFFFF;
const int LED_Yellow = LED_Red | LED_Green;
const int LED_Violet = LED_Red | LED_Blue;
const int LED_Cyan = LED_Blue | LED_Green;
const int LED_DimCyan = (LED_Blue | LED_Green) & LED_Half;
const int LED_DimWhite = LED_White & LED_Half;
// Used to attenuate the brightness of the LEDs, if desired. A shift of zero is full brightness
const int LEDBrightShift = 0;
const int LEDSingleMask = 0xFF - ((1<<LEDBrightShift)-1);
const int LEDBrightMask = LEDSingleMask | (LEDSingleMask << 8) | (LEDSingleMask << 16);
Working in the Simple IDE compiler so if possible I need it in C Code.
I can turn the RGBs on/off/set the colors... Now I want to fade from one color to another.
Anyone got some C code to smoothly fade from one color to another?
Looking for a procedure like this:
void Color_Fade(long _Start_Color, long _End_Color, int speedMS)
Here is example declarations for the color that I found in the Elev-8 flight controller.
// WS2812B RGB LED Module Variable Definitions
const int Extra_LED_Module_Count = 8; // Extra WS2812B RGB LED Module Count (Do not count the onboard WS2812B Module)
const int LED_COUNT = Extra_LED_Module_Count + 1; // + Onboard WS2812B
static long LEDValue[LED_COUNT]; // LED Outputs (Copied to the LEDs by the Sensors cog)
static long LEDModeColor; // Used to Set the LED Mode Color
const int FC_LED_Module = 0; // Flight Controller WS2812B RBG LED Module Index
//LED Brightness values - AND with color values to dim them
const int LED_Full = 0xffffff;
const int LED_Half = 0x7f7f7f;
const int LED_Quarter = 0x3f3f3f;
const int LED_Eighth = 0x1f1f1f;
const int LED_Dim = 0x0f0f0f;
//LED Color values
const int LED_Off = 0x000000;
const int LED_Red = 0x00FF00;
const int LED_Green = 0xFF0000;
const int LED_Blue = 0x0000FF;
const int LED_White = 0xFFFFFF;
const int LED_Yellow = LED_Red | LED_Green;
const int LED_Violet = LED_Red | LED_Blue;
const int LED_Cyan = LED_Blue | LED_Green;
const int LED_DimCyan = (LED_Blue | LED_Green) & LED_Half;
const int LED_DimWhite = LED_White & LED_Half;
// Used to attenuate the brightness of the LEDs, if desired. A shift of zero is full brightness
const int LEDBrightShift = 0;
const int LEDSingleMask = 0xFF - ((1<<LEDBrightShift)-1);
const int LEDBrightMask = LEDSingleMask | (LEDSingleMask << 8) | (LEDSingleMask << 16);
Comments
https://forums.parallax.com/post/quote/168435/Discussion_168435
It will be in Spin but ther is conversion software to make it "C"
Jim
This code is for individual RED, GREEN, and BLUE LED.
How to use a RGB LED
Mike
The morph() function will let you transition from one color to another. Put this into a timed loop.