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

Method map2RGB

libraries/map2colour/map2colour.cpp:45–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43
44
45uint32_t map2colour::map2RGB(float value)
46{
47 int index = 1;
48 // default values + out of lower range
49 uint8_t R = _Red[0];
50 uint8_t G = _Green[0];
51 uint8_t B = _Blue[0];
52
53 if (_values[0] < value)
54 {
55 if (value <= _values[6] )
56 {
57 // search the interval
58 while (_values[index] < value) index++;
59
60 // base value
61 R = _Red[index];
62 G = _Green[index];
63 B = _Blue[index];
64 // calculate the interpolation factor
65 // map2colourFast uses pre calculated dividers (costs 24 bytes extra RAM).
66 float factor = (_values[index] - value) / (_values[index] - _values[index - 1]);
67
68 // interpolate only if delta != 0
69 int delta = _Red[index] - _Red[index - 1];
70 if (delta != 0 ) R -= factor * delta;
71
72 delta = _Green[index] - _Green[index - 1];
73 if (delta != 0 ) G -= factor * delta;
74
75 delta = _Blue[index] - _Blue[index - 1];
76 if (delta != 0 ) B -= factor * delta;
77 }
78 else
79 {
80 // out of upper range
81 R = _Red[6];
82 G = _Green[6];
83 B = _Blue[6];
84 }
85 }
86 uint32_t colour = R;
87 colour <<= 8;
88 colour |= G;
89 colour <<= 8;
90 colour |= B;
91 return colour;
92}
93
94
95uint16_t map2colour::map2_565(float value)

Callers 1

unittestFunction · 0.80

Calls

no outgoing calls

Tested by 1

unittestFunction · 0.64