2021-12-04 15:32:57 -05:00
|
|
|
#pragma once
|
|
|
|
//
|
|
|
|
// FILE: map2colour.h
|
|
|
|
// AUTHOR: Rob Tillaart
|
2022-10-20 05:58:00 -04:00
|
|
|
// VERSION: 0.1.5
|
2021-12-04 15:32:57 -05:00
|
|
|
// PURPOSE: Arduino library for mapping a float to colour spectrum
|
|
|
|
// URL: https://github.com/RobTillaart/map2colour
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#include "Arduino.h"
|
|
|
|
|
2022-10-20 05:58:00 -04:00
|
|
|
#define MAP2COLOUR_LIB_VERSION (F("0.1.5"))
|
2021-12-09 09:05:02 -05:00
|
|
|
|
|
|
|
|
2022-10-20 05:58:00 -04:00
|
|
|
// https://www.w3.org/wiki/CSS/Properties/color/keywords
|
2021-12-09 09:05:02 -05:00
|
|
|
#define M2C_BLACK 0x00000000
|
|
|
|
#define M2C_SILVER 0x00C0C0C0
|
|
|
|
#define M2C_GRAY 0x00808080
|
|
|
|
#define M2C_WHITE 0x00FFFFFF
|
|
|
|
#define M2C_MAROON 0x00800000
|
|
|
|
#define M2C_RED 0x00FF0000
|
|
|
|
#define M2C_PURPLE 0x00800080
|
|
|
|
#define M2C_FUCHSIA 0x00FF00FF
|
|
|
|
#define M2C_GREEN 0x00008000
|
|
|
|
#define M2C_LIME 0x000FF000
|
|
|
|
#define M2C_OLIVE 0x00808000
|
|
|
|
#define M2C_YELLOW 0x00FFFF00
|
|
|
|
#define M2C_NAVY 0x00000080
|
|
|
|
#define M2C_BLUE 0x000000FF
|
|
|
|
#define M2C_TEAL 0x00008080
|
|
|
|
#define M2C_AQUA 0x0000FFFF
|
2021-12-04 15:32:57 -05:00
|
|
|
|
|
|
|
|
|
|
|
class map2colour
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
map2colour();
|
|
|
|
|
2022-10-20 05:58:00 -04:00
|
|
|
// values is an array of 7 values in ascending order
|
2021-12-09 09:05:02 -05:00
|
|
|
bool begin(float * values, uint32_t * colourMap = NULL);
|
2021-12-04 15:32:57 -05:00
|
|
|
uint32_t map2RGB(float value);
|
2021-12-09 09:05:02 -05:00
|
|
|
uint16_t map2_565(float value);
|
2021-12-04 15:32:57 -05:00
|
|
|
|
2021-12-09 09:05:02 -05:00
|
|
|
protected:
|
|
|
|
uint8_t _size = 7;
|
2021-12-04 15:32:57 -05:00
|
|
|
float * _values;
|
2021-12-09 09:05:02 -05:00
|
|
|
|
2022-10-20 05:58:00 -04:00
|
|
|
// default colours, split up per channel for performance.
|
2021-12-04 15:32:57 -05:00
|
|
|
uint8_t _Red[7] = { 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0xFF };
|
|
|
|
uint8_t _Green[7] = { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0xFF };
|
|
|
|
uint8_t _Blue[7] = { 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF };
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-12-09 09:05:02 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2022-10-20 05:58:00 -04:00
|
|
|
// DERIVED CLASS
|
2021-12-09 09:05:02 -05:00
|
|
|
//
|
2022-10-20 05:58:00 -04:00
|
|
|
// FASTER + MORE RAM
|
2021-12-09 09:05:02 -05:00
|
|
|
//
|
|
|
|
class map2colourFast : public map2colour
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
map2colourFast();
|
2022-10-20 05:58:00 -04:00
|
|
|
// values is an array of 7 values in ascending order
|
2021-12-09 09:05:02 -05:00
|
|
|
bool begin(float * values, uint32_t * colourMap = NULL);
|
|
|
|
uint32_t map2RGB(float value);
|
|
|
|
uint16_t map2_565(float value);
|
2021-12-04 15:32:57 -05:00
|
|
|
|
2021-12-09 09:05:02 -05:00
|
|
|
private:
|
|
|
|
float divFactor[6];
|
|
|
|
};
|
|
|
|
|
|
|
|
// -- END OF FILE --
|
2021-12-04 15:32:57 -05:00
|
|
|
|