Skip to content

tigoe/ColorConverter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ColorConverter Library for Arduino

This library allows you convert HSI color model values to RGB and RGBW values. I wrote it because I wanted this conversion for programmable LEDs like WS2812 or APA102C as well as for DMX-512 lighting control. It also allows you to convert RGB values to HSI values.

With HSI values, the overall power output of the LED remains constant, and the brightness of the eye remains constant, when fading across hues. This makes for more consistent color fades. For a better explanation, and the example code on which this is based, see Saiko LED’s blog post.

Commands

HSItoRGB

Syntax
ColorConverter.HSItoRGB(hue, saturation, intensity);
Parameters
  • hue (float) - color hue, 0 to 360 degrees

  • saturation (float) - color saturation, 0 to 100

  • intensity (float) - color intensity, 0 to 100

Returns

RGBColor (struct) - a structure containing four ints: red, green, blue, and white. All three or red, green, and blue will range from 0 to 255. For this function, white is always 0.

Example
RGBColor c = ColorConverter.HSItoRGB(hue, saturation, intensity);
Serial.print(c.red);
Serial.print(" ");
Serial.print(c.green);
Serial.print(" ");
Serial.println(c.blue);

HSItoRGBW

Syntax
ColorConverter.HSItoRGB(hue, saturation, intensity);
Parameters
  • hue (float) - color hue, 0 to 360 degrees

  • saturation (float) - color saturation, 0 to 100

  • intensity (float) - color intensity, 0 to 100

Returns

RGBColor (struct) - a structure containing four ints: red, green, blue, and white. All four will range from 0 to 255.

Example
RGBColor c = ColorConverter.HSItoRGB(hue, saturation, intensity);
Serial.print(c.red);
Serial.print(" ");
Serial.print(c.green);
Serial.print(" ");
Serial.print(c.blue);
Serial.print(" ");
Serial.print(c.white);

RGBtoHSI

Syntax
ColorConverter.RGBtoHSI(red, green,  blue);
Parameters
  • red (int) - red value, 0 to 255

  • green (int) - green value, 0 to 255

  • blue (int) - blue value, 0 to 255

Returns

HSIColor (struct) - a structure containing three floats: hue, saturation, and intensity.Hue will range from 0 to 359. Saturation and intensity will range from 0 to 100.

Example
HSIColor c = ColorConverter.RGBtoHSI(red, green, blue);
Serial.print(c.hue);
Serial.print(" ");
Serial.print(c.saturation);
Serial.print(" ");
Serial.println(c.intensity);

License

Notes

Copyright (c) Tom Igoe. All right reserved.

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

About

An Arduino library to convert RGB colors to HSI colors and vice versa

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages