Advertisement
atuline

rainbow_wave

Jan 3rd, 2020
10,053
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.27 KB | None | 0 0
  1.  
  2. /* rainbow_wave
  3.  
  4. By: Andrew Tuline
  5.  
  6. Date: Jan, 2020
  7.  
  8. A very simple rainbow wave and rainbow march using FastLED. That being said, I wouldn't normally use
  9. the fill_rainbow function in production code. Rather, I would use palettes.
  10.  
  11. */
  12.  
  13.  
  14. #define FASTLED_ALLOW_INTERRUPTS 0                            // Used for ESP8266.
  15. #include "FastLED.h"                                          // FastLED library.
  16.  
  17. #if FASTLED_VERSION < 3001000
  18. #error "Requires FastLED 3.1 or later; check github for latest code."
  19. #endif
  20.  
  21. // Fixed definitions cannot change on the fly.
  22. #define LED_DT 12                                             // Serial data pin
  23. #define LED_CK 11                                             // Clock pin for WS2801 or APA102
  24. #define COLOR_ORDER GRB                                       // It's GRB for WS2812B and GBR for APA102
  25. #define LED_TYPE WS2812                                       // What kind of strip are you using (APA102, WS2801 or WS2812B)?
  26. #define NUM_LEDS 60                                           // Number of LED's
  27.  
  28. // Initialize changeable global variables.
  29. uint8_t max_bright = 255;                                     // Overall brightness definition. It can be changed on the fly.
  30.  
  31. struct CRGB leds[NUM_LEDS];                                   // Initialize our LED array.
  32.  
  33.  
  34. void setup() {
  35.  
  36.   Serial.begin(115200);
  37.  
  38.   LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS);         // For WS2812B
  39. //  LEDS.addLeds<LED_TYPE, LED_DT, LED_CK, COLOR_ORDER>(leds, NUM_LEDS);   // For APA102 or WS2801
  40.  
  41.   FastLED.setBrightness(max_bright);
  42.   FastLED.setMaxPowerInVoltsAndMilliamps(5, 1000);              // FastLED power management set at 5V, 500mA
  43.  
  44. } // setup()
  45.  
  46.  
  47.  
  48. void loop () {
  49.  
  50.   rainbow_wave(10, 10);                                      // Speed, delta hue values.
  51.   FastLED.show();
  52.  
  53. } // loop()
  54.  
  55.  
  56.  
  57. void rainbow_wave(uint8_t thisSpeed, uint8_t deltaHue) {     // The fill_rainbow call doesn't support brightness levels.
  58.  
  59. // uint8_t thisHue = beatsin8(thisSpeed,0,255);                // A simple rainbow wave.
  60.  uint8_t thisHue = beat8(thisSpeed,255);                     // A simple rainbow march.
  61.  
  62.  fill_rainbow(leds, NUM_LEDS, thisHue, deltaHue);            // Use FastLED's fill_rainbow routine.
  63.  
  64. } // rainbow_wave()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement