2.6 KiB
map2colour
Arduino library for mapping a float to colour spectrum
Description
The map2colour library is used to make map a reading from a sensor, e.g. temperature or pressure, to a colour in the RGB spectrum.
The initial release uses 7 floats values that describe the range being mapped. These are passed to the library with begin(). These 7 floats must be in ascending order and are mapped upon the following colour array.
uint32_t colours[] =
{
// BLACK RED YELLOW GREEN ?? BLUE WHITE
0x00000000, 0x00FF0000, 0x00FFFF00, 0x0000FF00, 0x0000FFFF, 0x000000FF, 0x00FFFFFF
}
New values will be linear interpolated between the two points when needed.
Assume you initialize a float array
float tempArray[] = { -10, -10, 5, 15, 30, 60, 125 }; // note the double -10
A temperature of 0°C will be mapped between the 2nd and 3rd element so somewhere between RED and YELLOW. A temperature between 60°C and 125°C will be mapped between BLUE and WHITE.
This first version is to get hands on experience, a later version should support user defined colour maps.
Interface
- map2colour() constructor.
- bool begin(float * ar) load the array with 7 boundaries.
- uint32_t map2RGB(float value) returns RGB colour packed in an uint32_t. 0x00RRGGBB
Operation
See examples.
Future
- update documentation
0.2.0 thoughts
- make the colour map user defined - like multi-map
- between BLACK and a single colour. - intensity
- between a number of colours e.g. RED YELLOW GREEN or GREEN YELLOW RED
- fixed number of points is flex enough
- example with double entries
- temp -10, 5, 10, 30, 35, 60, 120
-
Red yellow black black yellow red red
- middle area 10..30 has no colour.