Something like this would make a good starting point.
// Color definitions
static const uint16_t BLACK = 0x0000;
static const uint16_t WHITE = 0xFFFF;
static const uint16_t NAVY = 0x000F;
static const uint16_t DARKGREEN = 0x03E0;
static const uint16_t DARKCYAN = 0x03EF;
static const uint16_t MAROON = 0x7800;
static const uint16_t PURPLE = 0x780F;
static const uint16_t ORANGE = 0xFD20;
static const uint16_t PINK = 0xF81F;
static const uint16_t OLIVE = 0x7BE0;
static const uint16_t BLUE = 0x001F;
static const uint16_t RED = 0xF800;
static const uint16_t GREEN = 0x07E0;
static const uint16_t CYAN = 0x07FF;
static const uint16_t MAGENTA = 0xF81F;
static const uint16_t YELLOW = 0xFFE0;
static const uint16_t BRIGHT_RED = 0xF810;
static const uint16_t LIGHT_GREY = 0xC618;//0x8410;
static const uint16_t DARK_GREY = 0x7BEF;//0x4208;
static const uint16_t GREENYELLOW = 0xAFE5;
class colorObj {
public:
colorObj(byte inRed, byte inGreen, byte inBlue);
colorObj(word color16);
colorObj(void);
void setColor(byte inRed, byte inGreen, byte inBlue);
void setColor(word color16);
void setColor(colorObj* inColor);
word getColor16(void);
byte getRed(void);
byte getGreen(void);
byte getBlue(void);
private :
byte red;
byte green;
byte blue;
};
// ****** colorObj ******
colorObj::colorObj(byte inRed, byte inGreen, byte inBlue) { setColor(inRed,inGreen,inBlue); }
//colorObj::colorObj(colorObj* inColor) { setColor(inColor); }
colorObj::colorObj(word inColor16) { setColor(inColor16); }
colorObj::colorObj(void) { setColor(0,0,0); }
void colorObj::setColor(byte inRed, byte inGreen, byte inBlue) {
red = inRed;
green = inGreen;
blue = inBlue;
}
void colorObj::setColor(word color16) {
switch(color16) {
case BLACK : //0x0000
red = 0;
green = 0;
blue = 0;
break;
case BLUE : //0x001F
red = 0;
green = 0;
blue = 255;
break;
case RED : //0xF800
red = 255;
green = 0;
blue = 0;
break;
case GREEN : //0x07E0
red = 0;
green = 255;
blue = 0;
break;
case CYAN : //0x07FF
red = 0;
green = 255;
blue = 255;
break;
case MAGENTA : //0xF81F
red = 255;
green = 0;
blue = 255;
break;
case YELLOW : //0xFFE0
red = 255;
green = 255;
blue = 0;
break;
case WHITE : //0xFFFF
red = 255;
green = 255;
blue = 255;
break;
default :
red = highByte(color16);
green = lowByte(color16>>5);
blue = lowByte(color16)<<3;
}
}
void colorObj::setColor(colorObj* inColor) {
red =inColor->getRed();
green =inColor->getGreen();
blue = inColor->getBlue();
}
// Copied from Adafruit'
word colorObj::getColor16(void) {
return ((red & 0xF8) << 8) | ((green & 0xFC) << 3) | (blue >> 3);
}
byte colorObj::getRed(void) { return red; }
byte colorObj::getGreen(void) { return green; }
byte colorObj::getBlue(void) { return blue; }
This is a simplified version of what I use. Extremely handy when you extend Adafruit's set & get pixleColor() to use colorObjects.
Actually mine includes this..
//Changes yourself by blending in some new color.
void colorObj::blend(colorObj* mixinColor,byte mixPercent) {
if (mixPercent>=100) { // If >= 100 means totally mixin color.
setColor(mixinColor);
} else if (mixPercent>0) { // So its NOT >= 100 but it is > 0.. Blend it.
mixMapper.setColors(this,mixinColor);
colorObj temp = mixMapper.Map(mixPercent);
setColor(&temp);
} // Otherwise, there is no change.
}
But that's more for the more advanced version.
Hope this helps.
-jim lee