atuline

FastLED palettes by number - not working

Jan 18th, 2021 (edited)
679
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.59 KB | None | 0 0
  1. /* Accessing palette via numbers instead of names. NOT WORKING!!!
  2.  *
  3.  * By: Andrew Tuline
  4.  *
  5.  * Date: January, 2021
  6.  *
  7.  * Reference: https://github.com/cloudwalking/tree/blob/master/tree/tree.ino
  8.  *
  9.  * There DOES, however appear to be a problem, because palettes[1] is black.
  10.  *
  11.  */
  12.  
  13. #include <FastLED.h>
  14.  
  15. #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
  16.  
  17. #define LED_DT 12
  18. #define COLOR_ORDER GRB
  19. #define LED_TYPE WS2812
  20. #define NUM_LEDS 30
  21.  
  22. #define BRIGHTNESS 64
  23.  
  24. struct CRGB leds[NUM_LEDS];                                   // Initialize our LED array.
  25.  
  26. const TProgmemRGBGradientPalettePtr palettes[] = {
  27.   (TProgmemRGBGradientPalettePtr)PartyColors_p,  // 0 purple yellow red orange blue
  28.   (TProgmemRGBGradientPalettePtr)CloudColors_p,  // 1 blue white
  29.   (TProgmemRGBGradientPalettePtr)OceanColors_p,  // 2 blue cyan white
  30.   (TProgmemRGBGradientPalettePtr)ForestColors_p, // 3 green blue
  31.   (TProgmemRGBGradientPalettePtr)LavaColors_p,   // 4 yellow orange red black
  32.   (TProgmemRGBGradientPalettePtr)HeatColors_p,   // 5 yellow orange red white
  33.   (TProgmemRGBGradientPalettePtr)RainbowColors_p // 6 rainbow
  34.   };
  35.  
  36. CRGBPalette16 currentPalette;
  37.  
  38.  
  39. void setup() {
  40.   Serial.begin(115200);
  41.   LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS);
  42.   FastLED.setBrightness(BRIGHTNESS);
  43. } // setup()
  44.  
  45.  
  46. void loop () {
  47.   uint8_t palette_num = (millis()/2000) % ARRAY_SIZE(palettes);
  48.   currentPalette = palettes[palette_num];
  49.   Serial.println(palette_num);
  50.   fill_palette(leds, NUM_LEDS, 0, (256/NUM_LEDS)+1, currentPalette, 255, NOBLEND);
  51.   FastLED.show();
  52. } // loop()
Add Comment
Please, Sign In to add comment