Skip to content

An Arduino library that simplifies blending colors with an RGB LED.

License

Notifications You must be signed in to change notification settings

ESikich/RGBLEDBlender

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Open Source Love GPL Licence

RGBLEDBlender

RGB blending and color library written for the Arduino.

by Erik Sikich
2016 November 22

See Colors.h for color definitions

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 the RGB pin numbers

Usage

Requires 3 PWM pins per RGBLEDBlender object. Objects may share the same pins in case of multiplexing or something similar.

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.

About

An Arduino library that simplifies blending colors with an RGB LED.

Resources

License

Stars

Watchers

Forks

Packages

No packages published