-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Kelvin2RGB.h
99 lines (80 loc) · 2.68 KB
/
Kelvin2RGB.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#pragma once
//
// FILE: Kelvin2RGB.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.3
// 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.3"))
#include "Arduino.h"
//
// 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
//
//
// 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
class Kelvin2RGB
{
public:
Kelvin2RGB();
void begin(); // empty function - obsolete?
void reset();
// temp = 0..65500 brightness = 0.0 .. 100.0%
void convert_TH(float temperature, float brightness = 100);
void convert_NB(float temperature, float brightness = 100);
float temperature() { return _temperature; };
float brightness() { return _brightness; };
// returns 0.0 .. 1.0
float red() { return _red; };
float green() { return _green; };
float blue() { return _blue; };
// red, green, blue should be in 0 .. 1.0 range
// brightness should be in 0..100%, Default = 100%,
// returns RGB.
uint32_t setRGB(float red, float green, float blue, float brightness = 100);
uint32_t RGB() { return _rgb; }; // 32 bit colour
uint16_t RGB565(); // 16 bit colour
// experimental 0.1.3
uint32_t CMYK();
uint32_t BGR();
private:
void _normalize();
float _temperature = 0;
float _brightness = 0;
float _red = 0;
float _green = 0;
float _blue = 0;
uint32_t _rgb = 0;
};
// -- END OF FILE --