mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-09-19 16:46:11 -04:00
0.2.0 Kelvin2RGB
This commit is contained in:
parent
28bce3a2fd
commit
062d7f2d43
@ -6,13 +6,23 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.1.7] - 2023-05
|
||||
## [0.2.0] - 2023-02-19
|
||||
- fix in Tanner Helland (very minor).
|
||||
- remove dead link from readme.md.
|
||||
- removed experimental from code.
|
||||
- change temperature #defines to **const uint16_t**. (compiler can check).
|
||||
- fix typo in **DLS_screenLow**
|
||||
- update unit tests
|
||||
- minor edits
|
||||
|
||||
----
|
||||
|
||||
## [0.1.7] - 2023-11-06
|
||||
- update readme.md
|
||||
- removed **reset()** ==> use **begin()**
|
||||
- edit examples.
|
||||
- minor edits
|
||||
|
||||
|
||||
## [0.1.6] - 2023-01-30
|
||||
- major improvement **BGR()**
|
||||
- minor improvement **CMYK()**
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: Kelvin2RGB.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.7
|
||||
// VERSION: 0.2.0
|
||||
// DATE: 2018-01-31
|
||||
// PURPOSE: Arduino library for converting temperature to RGB values
|
||||
// URL: https://github.com/RobTillaart/Kelvin2RGB
|
||||
@ -10,7 +10,7 @@
|
||||
#include "Kelvin2RGB.h"
|
||||
|
||||
|
||||
#define DIVIDE_255 (0.0039215686274509803921568627451)
|
||||
const float DIVIDE_255 = 0.0039215686274509803921568627451;
|
||||
|
||||
|
||||
Kelvin2RGB::Kelvin2RGB()
|
||||
@ -37,7 +37,7 @@ void Kelvin2RGB::begin()
|
||||
void Kelvin2RGB::convert_TH(float temperature, float brightness)
|
||||
{
|
||||
_temperature = constrain(temperature, 0, 65500);
|
||||
_brightness = constrain(brightness, 0, 100);
|
||||
_brightness = constrain(brightness, 0, 100); // used by normalize()
|
||||
|
||||
_red = _green = _blue = 0;
|
||||
float t = _temperature * 0.01;
|
||||
@ -54,7 +54,7 @@ void Kelvin2RGB::convert_TH(float temperature, float brightness)
|
||||
}
|
||||
else
|
||||
{
|
||||
_red = 329.698727466 * pow(t - 60, -0.1332047592);
|
||||
_red = 329.698727446 * pow(t - 60, -0.1332047592);
|
||||
_green = 288.1221695283 * pow(t - 60, -0.0755148492);
|
||||
_blue = 255;
|
||||
}
|
||||
@ -70,7 +70,7 @@ void Kelvin2RGB::convert_TH(float temperature, float brightness)
|
||||
void Kelvin2RGB::convert_NB(float temperature, float brightness)
|
||||
{
|
||||
_temperature = constrain(temperature, 0, 65500);
|
||||
_brightness = constrain(brightness, 0, 100);
|
||||
_brightness = constrain(brightness, 0, 100); // used by normalize()
|
||||
|
||||
_red = _green = _blue = 0;
|
||||
float t = _temperature * 0.01;
|
||||
|
@ -2,52 +2,52 @@
|
||||
//
|
||||
// FILE: Kelvin2RGB.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.7
|
||||
// VERSION: 0.2.0
|
||||
// DATE: 2018-01-31
|
||||
// PURPOSE: Arduino library for converting temperature to RGB values
|
||||
// URL: https://github.com/RobTillaart/Kelvin2RGB
|
||||
|
||||
|
||||
#define KELVIN2RGB_LIB_VERSION (F("0.1.7"))
|
||||
#define KELVIN2RGB_LIB_VERSION (F("0.2.0"))
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
|
||||
//
|
||||
// Based upon article Tanner Helland and Neil Bartlett
|
||||
// Library based upon article Tanner Helland and Neil Bartlett
|
||||
// http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/
|
||||
// http://www.zombieprototypes.com/?p=210
|
||||
// https://en.wikipedia.org/wiki/Color_temperature#Categorizing_different_lighting
|
||||
|
||||
|
||||
|
||||
// Values in table below based on
|
||||
// https://en.wikipedia.org/wiki/Color_temperature#Categorizing_different_lighting
|
||||
//
|
||||
// DAY LIGHT SETTING = TEMPERATURE
|
||||
//
|
||||
// based on https://en.wikipedia.org/wiki/Color_temperature#Categorizing_different_lighting
|
||||
//
|
||||
// DAY LIGHT SETTING TEMPERATURE
|
||||
//
|
||||
#define DLS_dark 0
|
||||
#define DLS_match 1700
|
||||
#define DLS_sodiumLamp 1700
|
||||
#define DLS_candleFlame 1850
|
||||
#define DLS_sunrise 1850
|
||||
#define DLS_sunset 1850
|
||||
#define DLS_bulb 2400
|
||||
#define DLS_bulbSoftWhite 2550
|
||||
#define DLS_LEDlamp 2700
|
||||
#define DLS_warmWhite 3000
|
||||
#define DLS_studioLight 3200
|
||||
#define DLS_studioCPlight 3350
|
||||
#define DLS_daylightHorizon 5000
|
||||
#define DLS_flashLight 5700
|
||||
#define DLS_xenonLight 6200
|
||||
#define DLS_dayLightBright 6500
|
||||
#define DLS_normal 6500
|
||||
#define DLS_screenlow 6500
|
||||
#define DLS_screenMed 8000
|
||||
#define DLS_screenHigh 9500
|
||||
#define DLS_polewardSky0 15000
|
||||
#define DLS_polewardSky1 19000
|
||||
#define DLS_polewardSky2 23000
|
||||
#define DLS_polewardSky3 27000
|
||||
const uint16_t DLS_dark = 0;
|
||||
const uint16_t DLS_match = 1700;
|
||||
const uint16_t DLS_sodiumLamp = 1700;
|
||||
const uint16_t DLS_candleFlame = 1850;
|
||||
const uint16_t DLS_sunrise = 1850;
|
||||
const uint16_t DLS_sunset = 1850;
|
||||
const uint16_t DLS_bulb = 2400;
|
||||
const uint16_t DLS_bulbSoftWhite = 2550;
|
||||
const uint16_t DLS_LEDlamp = 2700;
|
||||
const uint16_t DLS_warmWhite = 3000;
|
||||
const uint16_t DLS_studioLight = 3200;
|
||||
const uint16_t DLS_studioCPlight = 3350;
|
||||
const uint16_t DLS_daylightHorizon = 5000;
|
||||
const uint16_t DLS_flashLight = 5700;
|
||||
const uint16_t DLS_xenonLight = 6200;
|
||||
const uint16_t DLS_dayLightBright = 6500;
|
||||
const uint16_t DLS_normal = 6500;
|
||||
const uint16_t DLS_screenLow = 6500;
|
||||
const uint16_t DLS_screenMed = 8000;
|
||||
const uint16_t DLS_screenHigh = 9500;
|
||||
const uint16_t DLS_polewardSky0 = 15000;
|
||||
const uint16_t DLS_polewardSky1 = 19000;
|
||||
const uint16_t DLS_polewardSky2 = 23000;
|
||||
const uint16_t DLS_polewardSky3 = 27000;
|
||||
|
||||
|
||||
class Kelvin2RGB
|
||||
@ -58,14 +58,14 @@ public:
|
||||
// resets all variables to zero.
|
||||
void begin();
|
||||
[[deprecated("Use begin() instead")]]
|
||||
void reset() { begin(); }; // obsolete soon
|
||||
void reset() { begin(); }; // obsolete 0.3.0
|
||||
|
||||
// temperature = 0..65500 brightness = 0.0 .. 100.0%
|
||||
void convert_TH(float temperature, float brightness = 100.0);
|
||||
void convert_NB(float temperature, float brightness = 100.0);
|
||||
|
||||
float temperature();
|
||||
float brightness();;
|
||||
float brightness();
|
||||
|
||||
// returns 0.0 .. 1.0
|
||||
float red();
|
||||
@ -79,10 +79,8 @@ public:
|
||||
|
||||
uint32_t RGB(); // 32 bit colour (only 3 bytes used)
|
||||
uint16_t RGB565(); // 16 bit colour (2 bytes)
|
||||
|
||||
// Experimental 0.1.3
|
||||
uint32_t CMYK();
|
||||
uint32_t BGR();
|
||||
uint32_t CMYK();
|
||||
|
||||
|
||||
private:
|
||||
|
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018-2023 Rob Tillaart
|
||||
Copyright (c) 2018-2024 Rob Tillaart
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -16,10 +16,10 @@ Arduino library for converting temperature and brightness to RGB values.
|
||||
|
||||
## Credentials
|
||||
|
||||
This library is based upon an article of Tanner Helland and a related story by Neil Bartlett
|
||||
This library is based upon an article of Tanner Helland and a related story by Neil Bartlett.
|
||||
|
||||
- http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/
|
||||
- http://www.zombieprototypes.com/?p=210
|
||||
- http://www.zombieprototypes.com/?p=210 (dead link)
|
||||
- https://en.wikipedia.org/wiki/Color_temperature#Categorizing_different_lighting
|
||||
|
||||
There are more approximation formulas, some claim to be better,
|
||||
@ -90,9 +90,15 @@ Kelvin = (Fahrenheit - 523.67) * 0.5555555555;
|
||||
|
||||
The interface is straightforward:
|
||||
|
||||
#### Constructor
|
||||
|
||||
- **Kelvin2RGB()** constructor.
|
||||
- **void begin()** resets all internal values to 0.
|
||||
All colours, brightness and temperature.
|
||||
|
||||
|
||||
#### Convertors
|
||||
|
||||
- **void convert_TH(float temperature, float brightness = 100)**
|
||||
temperature = 0..65500 temperature below 1000 is not well defined.
|
||||
brightness = 0..100%,
|
||||
@ -106,6 +112,10 @@ The interface is straightforward:
|
||||
note this is different from Helland / Bartlett who both use an integer value 0 .. 255
|
||||
- **float green()** returns green channel weight 0.0 .. 1.0
|
||||
- **float blue()** returns blue channel weight 0.0 .. 1.0
|
||||
|
||||
|
||||
#### Color types
|
||||
|
||||
- **uint32_t setRGB(float red, float green, float blue, float brightness = 100)** sets RGB values
|
||||
red, green, blue should be in 0 .. 1.0 range. brightness should be in 0..100%, Default = 100%.
|
||||
returns a 24 bit RGB value,
|
||||
@ -121,9 +131,8 @@ The interface is straightforward:
|
||||
- **void reset()** => replaced by **begin()**
|
||||
|
||||
|
||||
## Operations
|
||||
## Predefined colors
|
||||
|
||||
See examples
|
||||
|
||||
|
||||
## Future
|
||||
@ -134,14 +143,13 @@ See examples
|
||||
|
||||
#### Should
|
||||
|
||||
- define constants like candleLight as parameter.
|
||||
- investigate other formulas.
|
||||
- investigate usability for RGB led strip.
|
||||
|
||||
#### Could
|
||||
|
||||
- separate brightness per colour channel to mimic "artificial illumination" (0.2.0 ?)
|
||||
- remove begin() or reset() ?
|
||||
- investigate other formulas.
|
||||
- investigate usability for RGB led strip.
|
||||
- separate brightness per colour channel to mimic "artificial illumination"
|
||||
- remove begin() or reset()?
|
||||
- add examples
|
||||
- ledstrip
|
||||
- use a "dirty flag" to minimize math operations.
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/Kelvin2RGB.git"
|
||||
},
|
||||
"version": "0.1.7",
|
||||
"version": "0.2.0",
|
||||
"license": "MIT",
|
||||
"frameworks": "*",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=Kelvin2RGB
|
||||
version=0.1.7
|
||||
version=0.2.0
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for converting temperature to RGB values
|
||||
|
@ -66,7 +66,7 @@ unittest(test_constants)
|
||||
assertEqual(DLS_xenonLight , 6200);
|
||||
assertEqual(DLS_dayLightBright , 6500);
|
||||
assertEqual(DLS_normal , 6500);
|
||||
assertEqual(DLS_screenlow , 6500);
|
||||
assertEqual(DLS_screenLow , 6500);
|
||||
assertEqual(DLS_screenMed , 8000);
|
||||
assertEqual(DLS_screenHigh , 9500);
|
||||
assertEqual(DLS_polewardSky0 , 15000);
|
||||
|
Loading…
Reference in New Issue
Block a user