Arduino library for interfacing with RGB+W leds. Implements HSI colorspace and Color temperature besides raw RGBW manipulation. Allows smooth non blocking fading between colors in all colorspaces. Corrects for non-linear brightness when using PWM.
Fading interpolation in Color temperature between two kelvin values results in natural colors, perfect for representing sunrise and sunset effects.
- Download the library from GitHub repository
- Open Arduino IDE
- Go to Sketch > Include Library > Add .ZIP Library...
- Search for the downloaded file
Include the library at the start of your code and initialize pins as OUTPUT
#include <RGBWLed.h>
RGBWLed (byte redPin, byte greenPin, byte bluePin, byte whitePin);
Simple functions to change the led color
// red, green and blue are [0..255] values, raw values
void writeRGBW(byte red, byte green, byte blue, byte white);
// red, green and blue are [0..255] values, dim correction
void setRGBW(byte red, byte green, byte blue, byte white);
// hue in degrees, saturation normalized [0..1] and intensity 8-bits [0..255]
void setHSI(float hue, float sat, byte in);
// temp in Kelvin, intensity 8-bits [0..255]
void setKelvin(float temp, byte in);
Asynchronus functions, void updateFade();
is needed to change led output
// Sets global intensity
void setIntensity(byte value);
// Fade functions, duration in seconds
void fadeHSI(HSI initcolour, HSI endcolour, unsigned int duration_s, unsigned int steps);
void fadeKelvin(Kelvin initcolour, Kelvin endcolour, unsigned int duration_s, unsigned int steps);
// Needs to be called periodically to update fade progress and apply global intensity
void updateFade(void);
// Helper functions
boolean isFading(void);
void pauseFade(void);
void resumeFade(void);
-
HSI conversions: Thanks to Brian Neltner from saikoled.com
-
Kelvin conversions: Thanks to Tanner Helland from tannerhelland.com