-- RGBMood Library --
Updated. V0.3
http://dl.dropbox.com/u/2155313/RGBMood.zip
--
Hi,
This is my first Library, I use it to control some RGB LEDs on a high level.
The library handles all the work for you.
Modes available:
FIX_MODE: The color doesn't change.
RANDOM_HUE_MODE: Color fades to random hue.
RAINBOW_HUE_MODE: Fading from red to red, going through all hue values.
RED_MODE: Random fade between redish colors.
BLUE_MODE: Random fade between blueish colors.
GREEN_MODE: Random fade between greenish colors.
FIRE_MODE: Fire effect. Like an electronic candle.
(More mode possible, ask for them )
There are many examples file provided in the library.
Here's a basic example:
Here's an example (provided in the library), this code make the leds fade between colors automatically (handling speed and time for you).
const int redPin = 9;
const int greenPin = 10;
const int bluePin = 11;
#include <RGBMood.h>
RGBMood m(redPin, greenPin, bluePin);
void setup() {
m.setMode(RGBMood::RANDOM_HUE_MODE); // Automatic random fade.
m.setHoldingTime(4000); // Keep the same color for 4 seconds before fading again.
m.setFadingSteps(150); // Fade with 150 steps.
m.setFadingSpeed(50); // Each step last 50ms. A complete fade takes 50*150 = 7.5 seconds
m.setHSB(random(359), 255, 255) // Random hue mode only change the hue so we first set the saturation and brightness to what we want.
}
void loop() {
m.tick(); // Update the colors.
}
You can also control the speed of the fadings:
setHoldingTime(4000) // How many ms do we keep a color before fading to a new one.
setFadingSpeed(100) // How many ms between each step when fading.
setFadingSteps(50) // How many steps for fading from a color to another.
Here's the API
void setHSB(uint16_t, uint16_t, uint16_t); // Set a fixed color from HSB color space.
void setRGB(uint16_t, uint16_t, uint16_t); // Set a fixed color from RGB color space.
void setRGB(uint32_t); // Using Color class.
void fadeHSB(uint16_t, uint16_t, uint16_t, bool = true); // Fade to a new color (given in HSB color space).
void fadeRGB(uint16_t, uint16_t, uint16_t); // Fade to a new color (given in RGB color space).
void fadeRGB(uint32_t); // Using Color class.
void tick(); // Update colors if needed. (call this in the loop function)
void hsb2rgb(uint16_t, uint16_t, uint16_t, uint16_t&, uint16_t&, uint16_t&); // Used internally to convert HSB to RGB
bool isFading() // True we are currently fading to a new color.
bool isStill() // True if we are not fading to a new color.
void setMode(Modes m) // Change the mode.
void setHoldingTime(uint16_t t) // How many ms do we keep a color before fading to a new one.
void setFadingSpeed(uint16_t t) // How many ms between each step when fading.
void setFadingSteps(uint16_t t) // How many steps for fading from a color to another.
uint16_t red() // The current red color.
uint16_t green() // The current green color.
uint16_t blue() // The current blue color.
If you need more explanations, feel free to ask
Any remark will be very appreciated !
Pollop.