kartonman

pixel fade to black

Aug 31st, 2021 (edited)
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include <FastLED.h>
  2.  
  3. #define NUM_LEDS 18
  4. #define LED_PIN 2
  5.  
  6. CRGB leds[NUM_LEDS];
  7.  
  8. uint8_t paletteIndex = 0;
  9.  
  10. CRGBPalette16 purplePalette = CRGBPalette16 (
  11. CRGB::DarkViolet,
  12. CRGB::DarkViolet,
  13. CRGB::DarkViolet,
  14. CRGB::DarkViolet,
  15.  
  16. CRGB::Magenta,
  17. CRGB::Magenta,
  18. CRGB::Linen,
  19. CRGB::Linen,
  20.  
  21. CRGB::Magenta,
  22. CRGB::Magenta,
  23. CRGB::DarkViolet,
  24. CRGB::DarkViolet,
  25.  
  26. CRGB::DarkViolet,
  27. CRGB::DarkViolet,
  28. CRGB::Linen,
  29. CRGB::Linen
  30. );
  31.  
  32.  
  33. CRGBPalette16 myPal = purplePalette;
  34.  
  35. void setup() {
  36. FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
  37. FastLED.setBrightness(50);
  38. }
  39.  
  40. void loop() {
  41.  
  42. EVERY_N_MILLISECONDS(50){
  43. //Switch on an LED at random, choosing a random color from the palette
  44. leds[random8(0, NUM_LEDS - 1)] = ColorFromPalette(myPal, random8(), 255, LINEARBLEND);
  45. }
  46.  
  47. // Fade all LEDs down by 1 in brightness each time this is called
  48. fadeToBlackBy(leds, NUM_LEDS, 1);
  49.  
  50. FastLED.show();
  51. }
Add Comment
Please, Sign In to add comment