Advertisement
atuline

FastLED palettes by number - working

Jan 19th, 2021 (edited)
1,398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.11 KB | None | 0 0
  1. /* Palette Pointers working
  2.  *
  3.  * By: Andrew Tuline
  4.  *
  5.  * Date: January, 2021
  6.  *
  7.  * Finally, a working version of code that programatically refers to built-in palettes by an index number.
  8.  *
  9.  */
  10.  
  11. #include <FastLED.h>
  12.  
  13. #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
  14.  
  15. #define LED_DT 12
  16. #define COLOR_ORDER GRB
  17. #define LED_TYPE WS2812
  18. #define NUM_LEDS 30
  19.  
  20. #define BRIGHTNESS 64
  21.  
  22. struct CRGB leds[NUM_LEDS];
  23.  
  24. FL_PROGMEM extern const TProgmemRGBPalette16 *const palettes[] = {
  25.   &PartyColors_p, &CloudColors_p, &OceanColors_p, &ForestColors_p,
  26.   &LavaColors_p, &HeatColors_p, &RainbowColors_p
  27.   };
  28.  
  29. CRGBPalette16 currentPalette;
  30.  
  31.  
  32. void setup() {
  33.   Serial.begin(115200);
  34.   LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS);
  35.   FastLED.setBrightness(BRIGHTNESS);
  36. } // setup()
  37.  
  38.  
  39. void loop () {
  40.   uint8_t palette_num = (millis()/2000) % sizeof(palettes);
  41.   currentPalette = *(TProgmemRGBPalette16 *) pgm_read_ptr_near(&palettes[palette_num]);
  42.   Serial.println(palette_num);
  43.   fill_palette(leds, NUM_LEDS, 0, (256/NUM_LEDS)+1, currentPalette, 255, NOBLEND);
  44.   FastLED.show();
  45. } // loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement