GY-63_MS5611/libraries/map2colour/map2colour.h

77 lines
2.1 KiB
C
Raw Normal View History

2021-12-04 15:32:57 -05:00
#pragma once
//
// FILE: map2colour.h
// AUTHOR: Rob Tillaart
2021-12-09 09:05:02 -05:00
// VERSION: 0.1.4
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"
2021-12-09 09:05:02 -05:00
#define MAP2COLOUR_LIB_VERSION (F("0.1.4"))
// https://www.w3.org/wiki/CSS/Properties/color/keywords
#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();
2021-12-09 09:05:02 -05:00
// values is an array of 7 values in ascending order
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
// 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
/////////////////////////////////////////////////////////////////////////
//
// DERIVED CLASS
//
// FASTER + MORE RAM
//
class map2colourFast : public map2colour
{
public:
map2colourFast();
// values is an array of 7 values in ascending order
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