{"id":13893849,"url":"https://github.com/RobTillaart/Kelvin2RGB","last_synced_at":"2025-07-17T08:31:09.870Z","repository":{"id":45331672,"uuid":"283819095","full_name":"RobTillaart/Kelvin2RGB","owner":"RobTillaart","description":"Arduino library for converting temperature to RGB values","archived":false,"fork":false,"pushed_at":"2024-04-13T09:05:31.000Z","size":37,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-19T06:34:31.273Z","etag":null,"topics":["arduino","color","colour","temperature"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RobTillaart.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"RobTillaart","custom":"https://www.paypal.me/robtillaart"}},"created_at":"2020-07-30T16:03:32.000Z","updated_at":"2024-01-12T18:14:32.000Z","dependencies_parsed_at":"2024-02-19T20:00:25.387Z","dependency_job_id":"48fdc063-4199-4db4-ba10-a815dd7333d7","html_url":"https://github.com/RobTillaart/Kelvin2RGB","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FKelvin2RGB","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FKelvin2RGB/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FKelvin2RGB/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FKelvin2RGB/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RobTillaart","download_url":"https://codeload.github.com/RobTillaart/Kelvin2RGB/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226243893,"owners_count":17594452,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arduino","color","colour","temperature"],"created_at":"2024-08-06T18:01:18.429Z","updated_at":"2025-07-17T08:31:09.864Z","avatar_url":"https://github.com/RobTillaart.png","language":"C++","funding_links":["https://github.com/sponsors/RobTillaart","https://www.paypal.me/robtillaart"],"categories":["C++"],"sub_categories":[],"readme":"\n[![Arduino CI](https://github.com/RobTillaart/Kelvin2RGB/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)\n[![Arduino-lint](https://github.com/RobTillaart/Kelvin2RGB/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/Kelvin2RGB/actions/workflows/arduino-lint.yml)\n[![JSON check](https://github.com/RobTillaart/Kelvin2RGB/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/Kelvin2RGB/actions/workflows/jsoncheck.yml)\n[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/Kelvin2RGB.svg)](https://github.com/RobTillaart/Kelvin2RGB/issues)\n\n[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/Kelvin2RGB/blob/master/LICENSE)\n[![GitHub release](https://img.shields.io/github/release/RobTillaart/Kelvin2RGB.svg?maxAge=3600)](https://github.com/RobTillaart/Kelvin2RGB/releases)\n[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/Kelvin2RGB.svg)](https://registry.platformio.org/libraries/robtillaart/Kelvin2RGB)\n\n\n# Kelvin2RGB\n\nArduino library for converting Kelvin temperature and brightness to RGB values.\n\n\n## Credentials\n\nThis library is based upon an article of Tanner Helland and a related story by Neil Bartlett.\n\n- http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/\n- http://www.zombieprototypes.com/?p=210 (dead link)\n- https://en.wikipedia.org/wiki/Color_temperature#Categorizing_different_lighting\n\nThere are more approximation formulas, some claim to be better,\nhowever these are not investigated. On request these can be added.\n\n\n## Description\n\nThe library converts a temperature in Kelvin and a brightness (0..100%)\n to three numbers **red**, **green** and **blue**.\nThese numbers are weights can be used to correct a colour image for virtual white temperature.\n\nThere are two convert functions where the **convert_NB()** is claimed to be\nthe more accurate one.\n\nWith the numbers **red**, **green** and **blue** calculated one can convert images \nso they will look more like taken with candle light, sunrise or sunset etc.\n\n\n**pseudo code**\n```cpp\nKelvin2RGB KRGB;\n\nKRGB.convert(1850, 100);  // sunrise light factors\n\nfor each pixel in image\n{\n  red   *= KRGB.red();\n  green *= KRGB.green();\n  blue  *= KRGB.blue();\n  drawPixel();\n}\n```\n\nThe numbers can also be used to reduce the blue channel so it has less effect \non \"getting sleepy\".\n\nThe library uses floats for the R,G and B weights to keep values as accurate as possible.\nEspecially with images with more than 8 bits per channel this is preferred.\nThat said it is also possible to use this on a 565 image or to adjust colour lookup tables.\n\n\n### Celsius and Fahrenheit\n\nTo use Celsius or Fahrenheit with the **Kelvin2RGB** library, \none need to convert that temperature to Kelvin.\n\n```cpp\nKelvin = Celsius + 273.15;\nKelvin = (Fahrenheit - 32) * 5.0 / 9.0 - 273.15;\n// or shorter\nKelvin = (Fahrenheit - 523.67) * 0.5555555555;\n```\n\n\n### Related\n\n- https://github.com/RobTillaart/Kelvin2RGB\n- https://github.com/RobTillaart/map2colour   map float onto a colour(gradient).\n- https://github.com/RobTillaart/Temperature  temperature scale convertors\n\n\n## Interface\n\n```cpp\n#include \"Kelvin2RGB.h\"\n```\n\nThe interface is straightforward:\n\n### Constructor\n\n- **Kelvin2RGB()** constructor.\n- **void begin()** resets all internal values to 0. \n    All colours, brightness and temperature.\n\n\n### Convertors\n\n- **void convert_TH(float temperature, float brightness = 100)**\n    temperature = 0..65500   temperature below 1000 is not well defined.\n    brightness = 0..100%,\n- **void convert_NB(float temperature, float brightness = 100)**\n    temperature = 0..65500   temperature below 1000 is not well defined.\n    brightness = 0..100%,\n    Is a bit more accurate and slightly slower (few %). Read link above for more information.\n- **float temperature()** returns temperature, to check the value used.\n- **float brightness()** returns brightness, to check the value used.\n- **float red()** returns red channel weight 0.0 .. 1.0\n    note this is different from Helland / Bartlett who both use an integer value 0 .. 255\n- **float green()** returns green channel weight 0.0 .. 1.0\n- **float blue()** returns blue channel weight 0.0 .. 1.0\n\n\n### Color types\n\n- **uint32_t setRGB(float red, float green, float blue, float brightness = 100)** sets RGB values\n    red, green, blue should be in 0 .. 1.0 range. brightness should be in 0..100%, Default = 100%.\n    returns a 24 bit RGB value,\n- **uint32_t RGB()** returns a 24 bit RGB value, 0 .. 16777215\n    more efficient than 3 floats for communication.\n- **uint16_t RGB565()** returns a 16 bit RGB value, 5 bits for red, 6 for green and 5 for blue.\n- **uint32_t BGR()** returns a 24 bit BGR value, 0 .. 16777215\n- **uint32_t CMYK()** returns a 32 bit = 4 byte CMYK value,\n\n\n### Obsolete\n\n- **void reset()** =\u003e replaced by **begin()**\n\n\n## Predefined colors\n\n\n```cpp\nconst uint16_t DLS_dark            =     0;\nconst uint16_t DLS_match           =  1700;\nconst uint16_t DLS_sodiumLamp      =  1700;\nconst uint16_t DLS_candleFlame     =  1850;\nconst uint16_t DLS_sunrise         =  1850;\nconst uint16_t DLS_sunset          =  1850;\nconst uint16_t DLS_bulb            =  2400;\nconst uint16_t DLS_bulbSoftWhite   =  2550;\nconst uint16_t DLS_LEDlamp         =  2700;\nconst uint16_t DLS_warmWhite       =  3000;\nconst uint16_t DLS_studioLight     =  3200;\nconst uint16_t DLS_studioCPlight   =  3350;\nconst uint16_t DLS_daylightHorizon =  5000;\nconst uint16_t DLS_flashLight      =  5700;\nconst uint16_t DLS_xenonLight      =  6200;\nconst uint16_t DLS_dayLightBright  =  6500;\nconst uint16_t DLS_normal          =  6500;\nconst uint16_t DLS_screenLow       =  6500;\nconst uint16_t DLS_screenMed       =  8000;\nconst uint16_t DLS_screenHigh      =  9500;\nconst uint16_t DLS_polewardSky0    = 15000;\nconst uint16_t DLS_polewardSky1    = 19000;\nconst uint16_t DLS_polewardSky2    = 23000;\nconst uint16_t DLS_polewardSky3    = 27000;\n```\n\n\n## Future\n\n#### Must\n\n- improve documentations.\n\n#### Should\n\n\n#### Could\n\n- investigate other formulas.\n- investigate usability for RGB led strip.\n- separate brightness per colour channel to mimic \"artificial illumination\"\n- add examples\n  - ledstrip\n- use a \"dirty flag\" to minimize math operations.\n\n#### Wont\n\n- investigate **RGB_10_12_10()**\n  - nowhere used (not found)\n\n\n## Support\n\nIf you appreciate my libraries, you can support the development and maintenance.\nImprove the quality of the libraries by providing issues and Pull Requests, or\ndonate through PayPal or GitHub sponsors.\n\nThank you,\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRobTillaart%2FKelvin2RGB","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRobTillaart%2FKelvin2RGB","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRobTillaart%2FKelvin2RGB/lists"}