Skip to content

Instantly share code, notes, and snippets.

@StefanPetrick
StefanPetrick / circular_matrix.ino
Last active March 25, 2024 04:07
A 2d matrix mapped onto a circular led setup
/*
* A FastLED example showing how to
* map a virtual 2d matrix onto a circular led setup
*
* limitations: works so far only up to 255 leds
*
* written by Stefan Petrick 2016
*/
#include "FastLED.h"
@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,