HSB RGB Arduino Color Library

Views: 3818 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 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 Arduino HSB RGB Color library 
 * http://www.lucidtronix.com/tutorials/19
 * Control rgb color by specifying
 * Hue saturation and brightness.
 * This code shows a rainbow
 */

#include <color.h>
// these are the pins connected to
// the RGB LEDs.  They must be PWM capable
int leds[] = {5,6,9}; 
Color cur_color = Color(1,1,1);
float hue = 0;
void setup()  // run once, when the sketch starts                  
{
  for(int i = 0 ; i < 3; i++ ){
    pinMode(leds[i], OUTPUT); 
  }
}

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

void rainbow(){
  hue += 0.06;
  if ( hue >=1 ) hue = 0;
  float sat = 1.0;
  float val = 0.4;
  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);
}

Arduino Color Library

Unzip the file and then add the folder to your arduino libraries folder. Restart arduino and you should be ready to go. See this great adafruit tutorial for details on arduino library installation.
Click Here to Download: Arduino Color Library
Permalink: http://lucidtronix.com/tutorials/19
Viewed: 5:23AM, May 24
Viewed: 5:16AM, May 24
Viewed: 5:14AM, May 24
Viewed: 5:09AM, May 24
Viewed: 5:04AM, May 24
Viewed: 4:54AM, May 24
Viewed: 4:52AM, May 24
Viewed: 4:44AM, May 24
Viewed: 4:42AM, May 24
Viewed: 4:26AM, May 24
Viewed: 4:21AM, May 24
Viewed: 4:13AM, May 24
Viewed: 4:12AM, May 24
Viewed: 4:12AM, May 24
Viewed: 4:12AM, May 24
Go to page: 1 2 3