Arduino Playground is read-only starting December 31st, 2018. For more info please look at this Forum Post

RGBLEDBlender

RGB blending and color library created for the Arduino.

Written by Erik Sikich 2016

Download from Github here.

Overview of functions

  • Blend - Blends two colors together
  • Random - Blends randomly generated colors together
  • RandomCycle - Randomly cycles through a list of colors
  • Cycle - Cycles through a list of colors
  • Update - Call to update color
  • Hold - Holds a color
  • TurnOff - Turns off the LED
  • GetColor - Returns current color
  • SetPins -Sets RGB pins

Usage

Requires 3 PWM pins.

To blend arbitrary colors together, call the Blend() fuction once and then repeatedly call Update()

my_blender.Blend(_RED, _YELLOW, blend_time);

uint32_t blend_time = 1000;
uint32_t done = millis() + blend_time;

while(done > millis()){
my_blender.Update();
}

For Random(), RandomCycle(), and Cycle(), just repeatedly call the function.

Color color_list[6] = {_RED, _ORANGE, _YELLOW, _GREEN, _BLUE, _PURPLE};

while(true){
my_blender.RandomCycle(color_list, 6, 1000);
}

Color math and assignments

Colors can be added, subtracted, divided and multiplied either by each other or constants.

Color my_color = {10, 15, 20};
Color my_color2 = {1, 2 ,3};
my_color *= 2;
//my_color would now be == {20, 30, 40}

my_color += my_color2;
//my_color would now be == {21, 32, 43}

NOTE: Be vigilant when doing this, as the Color struct is made of int16_t's. Be sure to check your values as writing values < 0 or > 255 will cause under/overflow issues and you will not get the colors you expect.

Pre-defined color definitions

Pulled from here.