Advertisement
atuline

rainbow_pal

Jun 21st, 2020
1,895
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.43 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 standard rainbow.
  8.  *
  9.  * This routine 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.
  11.  *
  12.  */
  13.  
  14. #include "FastLED.h"                                          // FastLED library.
  15.  
  16. // Fixed definitions cannot change on the fly.
  17. #define LED_DT D4                                             // Data pin to connect to the strip.
  18. #define COLOR_ORDER GRB                                       // It's GRB for WS2812 and BGR for APA102.
  19. #define LED_TYPE WS2812                                       // Using APA102, WS2812, WS2801. Don't forget to modify LEDS.addLeds to suit.
  20. #define NUM_LEDS 30                                           // Number of LED's.
  21.  
  22. struct CRGB leds[NUM_LEDS];
  23.  
  24. CRGBPalette16 currentPalette = PartyColors_p;
  25.  
  26.  
  27.  
  28. void setup() {
  29.  
  30.   delay(1000);
  31.  
  32.   LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS);
  33.  
  34. } // setup()
  35.  
  36.  
  37.  
  38. void loop () {
  39.  
  40.     rainbow_pal();
  41.     FastLED.show();
  42.  
  43. } // loop()
  44.  
  45.  
  46.  
  47. void rainbow_pal() {
  48.  
  49.   uint16_t locn = millis()/20;
  50.   uint8_t hueChg = 5;
  51.  
  52.   for (int i=0; i<NUM_LEDS; i++) {
  53.     leds[i] = ColorFromPalette(currentPalette, locn + i*hueChg, 255, LINEARBLEND);
  54.   }
  55.  
  56. } // rainbow_pal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement