atuline

Palette rainbow march with FastLED

Apr 1st, 2020
602
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. /* Simple rainbow march using palettes
  2. *
  3. * By: Andrew Tuline
  4. *
  5. * Date: January, 2018
  6. *
  7. * This rainbow march uses palettes instead of the fill_rainbow() function.
  8. *
  9. * This routine also uses millis() instead of the dreaded delay statement for timing. As a result, the frame rate will be high
  10. * so that button or other polling routines can be added in the future. It was also animated at the same rate no matter
  11. * which Arduino you're using.
  12. *
  13. */
  14.  
  15. #include "FastLED.h" // FastLED library.
  16.  
  17. // Fixed definitions cannot change on the fly.
  18. #define LED_DT D4 // Data pin to connect to the strip.
  19. #define COLOR_ORDER GRB // It's GRB for WS2812 and BGR for APA102.
  20. #define LED_TYPE WS2812 // Using APA102, WS2812, WS2801. Don't forget to modify LEDS.addLeds to suit.
  21. #define NUM_LEDS 30 // Number of LED's.
  22.  
  23. struct CRGB leds[NUM_LEDS];
  24.  
  25. CRGBPalette16 currentPalette = PartyColors_p;
  26.  
  27.  
  28.  
  29. void setup() {
  30.  
  31. delay(1000);
  32.  
  33. LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS);
  34.  
  35. } // setup()
  36.  
  37.  
  38.  
  39. void loop () {
  40.  
  41. rainbow_pal();
  42. FastLED.show();
  43.  
  44. } // loop()
  45.  
  46.  
  47.  
  48. void rainbow_pal() {
  49.  
  50. uint16_t locn = millis()/20;
  51. uint8_t hueChg = 5;
  52.  
  53. for (int i=0; i<NUM_LEDS; i++) {
  54. leds[i] = ColorFromPalette(currentPalette, locn + i*hueChg, 255, LINEARBLEND);
  55. }
  56.  
  57. } // rainbow_pal
Advertisement
Add Comment
Please, Sign In to add comment