atuline

purplepalette.ino

Nov 25th, 2020
501
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <FastLED.h>
  2.  
  3. #define NUM_LEDS 30
  4. #define LED_PIN 12
  5. #define BRIGHTNESS 100
  6.  
  7. CRGB leds[NUM_LEDS];
  8. uint8_t ColorIndex[NUM_LEDS];
  9.  
  10.  
  11.  
  12. DEFINE_GRADIENT_PALETTE (BlueAndPurp)
  13. {
  14. 0,   0,  212, 255,              //Cyan
  15. 61,  96, 4,   192,             //Purp
  16. 125, 9,  9,   121,             //Dark Blue
  17. 194, 96, 4,   192,             //Purp
  18. 255, 0,  212, 255,             //Cyan
  19. };
  20.  
  21. CRGBPalette16 myPal = BlueAndPurp;
  22.  
  23.  
  24. void setup()
  25. {
  26.   Serial.begin(115200);
  27.   LEDS.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);  // Use this for WS2801 or APA102
  28.   FastLED.setBrightness(BRIGHTNESS);
  29.  
  30.   // This is required by withArray(), but not required by withoutArray().
  31.   for(int i = 0; i < NUM_LEDS; i++) ColorIndex[i] = random8();
  32.  
  33. }
  34.  
  35. void loop() {
  36.  
  37. //  withArray();
  38.   withoutArray();
  39.  
  40.     FastLED.show();
  41. }
  42.  
  43.  
  44. // This method requires an initializer AND an array to store state information.
  45. void withArray() {
  46.    
  47.    for(int i = 0; i < NUM_LEDS; i++) {
  48.     leds[i] = ColorFromPalette(myPal, ColorIndex[i], 255);
  49.       if(i==0) Serial.println(ColorIndex[i]);
  50.   }
  51.  
  52.   EVERY_N_MILLISECONDS(10) {
  53.     for(int i = 0; i < NUM_LEDS; i++) ColorIndex[i]++;
  54.   }
  55. }
  56.  
  57.  
  58. // This method doesn't require an initializer OR an array to store state information.
  59. void withoutArray() {
  60.  
  61.   random16_set_seed(535);
  62.  
  63.   for(int i = 0; i < NUM_LEDS; i++) {
  64.     leds[i] = ColorFromPalette(myPal, random8()+millis()/10, 255);
  65.   }
  66. }
RAW Paste Data