Skip to content

Instantly share code, notes, and snippets.

@morningdew76
morningdew76 / ColorFromPalette12.ino
Last active March 17, 2023 20:52
ColorFromPalette12, a 12-bit ColorFromPalette function
CRGB ColorFromPalette12(CRGBPalette16 pal, uint16_t index, uint8_t brightness, TBlendType blendType) {
//index is a 12-bit number, range 0-4095
//uint8_t hi4 = lsrX4(index);
//uint8_t lo4 = index & 0x0F;
uint8_t hi4 = (index & 0x0F00) >> 8; //***shift 8 bits to the right instead of 4
uint8_t lo8 = index & 0xFF; //***keep right 8 bytes instead of right 4 bytes
// const CRGB* entry = &(pal[0]) + hi4;
// since hi4 is always 0..15, hi4 * sizeof(CRGB) can be a single-byte value,