Coder Social home page Coder Social logo

colorconverter's Introduction

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

colorconverter's People

Contributors

tigoe avatar

Watchers

James Cloos avatar Sandeep Mistry avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.