Feedback!

HSB RGB Arduino Color Library

Views: 14772 Difficulty: 2 Status: Complete
Screen_shot_2013-01-17_at_7.58.46_pm

Here is another arduino library to handle Hue, Saturation, and Brightness as well as Red, Green, and Blue color models.

Screens speak of color in terms of 3 channels: Red, Green and Blue. Humans tend to think of colors in 3 channels too, but the channels that seem more natural usually are Hue, Saturation and Brightness. Here is an arduino color library so you too can specify colors by their hue! We use this code in our RGB Rainbow Sun and HSB RGB Sketcher. If you need help learning how to install libraries in arduino check out this thorough Adafruit tutorial. We use this library to draw colors on LCD screens, for example see the HSB RGB Sketcher Tutorial and onto RGB LEDs in the Sun Kit.

Arduino Color Icon

Screen_shot_2013-01-17_at_7.58.46_pm
Color Icon!

Color Wheel on LEO Gamer

Here we are using the Arduino color code to display a color wheel on the LEO Gamer.

Color Code Example

This code show a basic example of using the color library to make a rainbow appear on RGB LEDs. By varying the hue the rainbow function moves across the whole visible color spectrum.
/* LucidTronix HSB RGB Color Library
 * For instructions, details and schematic, See:
 * http://www.lucidtronix.com/tutorials/19
 */

#include <Color.h>

// these are the pins connected to the RGB LEDs
int leds[] = {9,10,11}; 
Color cur_color = Color(1,1,1);
float hue = 0;

// run once, when the sketch starts
void setup()                    
{
  for(int i = 0 ; i < 3; i++ ){
    pinMode(leds[i], OUTPUT);
    digitalWrite(leds[i], LOW);
    delay(300); 
    digitalWrite(leds[i], HIGH);
    delay(300);
  }
}

// run over and over again
void loop()                   
{
  display_color(cur_color);
  rainbow();
}

void rainbow(){
  hue += 0.06;
  if ( hue >=1 ) hue = 0;
  float sat = 0.8;
  float val = 0.2;
  cur_color.convert_hcl_to_rgb(hue,sat,val);
  display_color(cur_color);
  delay(20);
}

void display_color(Color c){
  analogWrite(leds[0], c.red);
  analogWrite(leds[1], c.green);
  analogWrite(leds[2], c.blue);
  delay(100);
}

Download the Color Library from Github

Grab the latest code here! Download and unizp into your Arduino libraries folder.
Permalink: http://lucidtronix.com/tutorials/19
A library to interface Arduino code with the 3 Axis L3G4200D gyroscope....
An arduino library for the MMA8453 Triple Axis Accelerometer...
Control the hue, value and saturation on this pocket-sized joystick drawing machine....
A wearable real-time clock with vibrant color display....
Coupling the HMC5883L Compass with our color library turns the Wearable Wayfinder into a handy naviga...
Think of it like a shift register for Pulse Width Modulation (PWM)....
Put images onto your circuit boards with eagle silkscreen footprint library....
Control a 120v outlet with a 5V arduino....