Skip to content
An Arduino library to convert RGB colors to HSI colors and vice versa
C++
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
src
.gitattributes
.gitignore
README.adoc
keywords.txt
library.properties

README.adoc

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

ColorConverter

Syntax
ColorConverter converter;
Parameters

none

Returns

void

Notes

Creates a new instance of the library.

HSItoRGB

Syntax
converter.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 = converter.HSItoRGB(hue, saturation, intensity);
Serial.print(c.red);
Serial.print(" ");
Serial.print(c.green);
Serial.print(" ");
Serial.println(c.blue);

HSItoRGBW

Syntax
converter.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 = converter.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
converter.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 = converter.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

You can’t perform that action at this time.