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.
ColorConverter.HSItoRGB(hue, saturation, intensity);
hue (float) - color hue, 0 to 360 degrees
saturation (float) - color saturation, 0 to 100
intensity (float) - color intensity, 0 to 100
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.
RGBColor c = ColorConverter.HSItoRGB(hue, saturation, intensity); Serial.print(c.red); Serial.print(" "); Serial.print(c.green); Serial.print(" "); Serial.println(c.blue);
ColorConverter.HSItoRGB(hue, saturation, intensity);
hue (float) - color hue, 0 to 360 degrees
saturation (float) - color saturation, 0 to 100
intensity (float) - color intensity, 0 to 100
RGBColor (struct) - a structure containing four ints: red, green, blue, and white. All four will range from 0 to 255.
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);
ColorConverter.RGBtoHSI(red, green, blue);
red (int) - red value, 0 to 255
green (int) - green value, 0 to 255
blue (int) - blue value, 0 to 255
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.
HSIColor c = ColorConverter.RGBtoHSI(red, green, blue); Serial.print(c.hue); Serial.print(" "); Serial.print(c.saturation); Serial.print(" "); Serial.println(c.intensity);
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