Advertisement
atuline

FastLED blend

Jun 9th, 2015
947
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.09 KB | None | 0 0
  1. /* blend
  2.  
  3. By: Andrew Tuline
  4.  
  5. Date: June, 2015
  6.  
  7. Here's a simple method to blend between a couple of colours across a strand of LED's. It doesn't really make good use of
  8. the individually addressable aspect of these LED's.
  9.  
  10. It uses FastLED's:
  11.  
  12. - blend() function to blend between two colours
  13. - sin8() function to provide a smooth varying input to blend().
  14.  
  15. */
  16.  
  17. #include "FastLED.h"                                          // FastLED library. Preferably the latest copy of FastLED 2.1.
  18.  
  19. // Fixed global definitions.
  20. #define LED_DT 12                                             // Data pin to connect to the strip.
  21. #define LED_CK 11
  22. #define COLOR_ORDER BGR                                       // Are they RGB, GRB or what??
  23. #define LED_TYPE APA102                                       // Don't forget to change LEDS.addLeds
  24. #define NUM_LEDS 20                                           // Number of LED's.
  25.  
  26. // Initialize changeable global variables.
  27. uint8_t max_bright = 16;                                      // Overall brightness definition. It can be changed on the fly.
  28.  
  29. struct CRGB leds[NUM_LEDS];                                   // Initialize our LED array.
  30.  
  31. // Define variables used by the sequence.
  32. uint8_t thisdelay = 25;                                        // Our delay.
  33. int mysine=0;                                                  // Input for a sinewave. Saves on counting up/down.
  34.  
  35.  
  36. void setup() {
  37.   delay(1000);                                                 // Power-up safety delay or something like that.
  38.   Serial.begin(57600);
  39.   LEDS.addLeds<LED_TYPE, LED_DT, LED_CK, COLOR_ORDER>(leds, NUM_LEDS);  // Use this for WS2801 or APA102
  40.   FastLED.setBrightness(max_bright);
  41. } // setup()
  42.  
  43. void loop () {
  44.   blendme();
  45.   FastLED.show();
  46.   delay(thisdelay);
  47.   mysine++;
  48. } // loop()
  49.  
  50.  
  51. void blendme() {
  52.   for (uint8_t i = 0; i<NUM_LEDS; i++) {
  53.  
  54.     leds[i] = blend(CRGB::Red, CRGB::Blue, sin8(mysine));
  55.  
  56. //  If you forgot about the blend function, you can always use this instead:
  57. //  leds[i].r = sin8(mysine);
  58. //  leds[i].b = 255 - sin8(mysine);
  59.   }
  60. } // blendme()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement