MCPcopy Create free account
hub / github.com/RobTillaart/Arduino / convert_TH

Method convert_TH

libraries/Kelvin2RGB/Kelvin2RGB.cpp:42–68  ·  view source on GitHub ↗

/////////////////////////////////////////////////////////// Tanner Helland formulas

Source from the content-addressed store, hash-verified

40// Tanner Helland formulas
41//
42void Kelvin2RGB::convert_TH(float temperature, float brightness)
43{
44 _temperature = constrain(temperature, 0, 65500);
45 _brightness = constrain(brightness, 0, 100);
46
47 _red = _green = _blue = 0;
48 float t = _temperature * 0.01;
49
50 if (t <= 66)
51 {
52 _red = 255;
53 _green = (99.4708025861 * log(t)) - 161.1195681661;
54 if (t > 19)
55 {
56 _blue = (138.5177312231 * log(t - 10)) - 305.0447927307;
57 }
58 else _blue = 0;
59 }
60 else
61 {
62 _red = 329.698727466 * pow(t - 60, -0.1332047592);
63 _green = 288.1221695283 * pow(t - 60, -0.0755148492);
64 _blue = 255;
65 }
66
67 _normalize();
68}
69
70
71////////////////////////////////////////////////////////////////

Callers 1

unittestFunction · 0.80

Calls

no outgoing calls

Tested by 1

unittestFunction · 0.64