Jingleby

FastLED Analog Strip Gradient Fade

Mar 2nd, 2016
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. //Main Goal: Analog Strip fades from one defined hue to a second defined hue
  2. //Secondary Goal: 4 analog strips repeating this action with each delayed slightly. (2 Variables to define delay amount and overall speed fade occurs)
  3.  
  4. #include "FastLED.h"
  5.  
  6. // fast led constants
  7. // #define DATA_PIN 3 // change to your data pin
  8. // #define COLOR_ORDER GRB // if colors are mismatched; change this
  9. #define NUM_LEDS 1 // change to the number of LEDs in your strip
  10.  
  11. #define REDPIN 5
  12. #define GREENPIN 6
  13. #define BLUEPIN 3
  14.  
  15. // change WS2812B to match your type of LED, if different
  16. // list of supported types is here:
  17. // https://github.com/FastLED/FastLED/wiki/Overview
  18. //#define LED_TYPE WS2812B
  19.  
  20. // this creates an LED array to hold the values for each led in your strip
  21. CRGB leds[NUM_LEDS];
  22.  
  23. // fill_gradient variables (except direction as I wasn't sure what variable type to make it?)
  24. int start_pixel = 0;
  25. int end_pixel = 0;
  26. CHSV start_hue = CHSV(0, 255, 100);
  27. CHSV end_hue = CHSV(180, 255, 100);
  28.  
  29. void showAnalogRGB( const CRGB& rgb)
  30. {
  31. analogWrite(REDPIN, rgb.r );
  32. analogWrite(GREENPIN, rgb.g );
  33. analogWrite(BLUEPIN, rgb.b );
  34. }
  35.  
  36.  
  37. void setup()
  38. {
  39. // the wiki features a much more basic setup line:
  40. // FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
  41. }
  42.  
  43. void loop()
  44. {
  45. /*
  46. arguments are:
  47. array: the name of your "CRGB name[NUM_LEDS] definition above
  48. start_led: which index number (0 is first pixel) to start with?
  49. start_hue: CHSV form (hue, sat, bright) of color/brightness for start led
  50. end_led: which is the last pixel in the gradient?
  51. end_hue: CHSF form for color of last pixel in gradient
  52. direction: thinking of a 0-255 color wheel, which direction should the
  53. gradient ramp through? Change the below to SHORTEST_HUES and you'll
  54. see that it goes red to blue through violet. Compare that to this, which
  55. goes the "long way" through yellow, green, and cyan.
  56. directions explained here: http://fastled.io/docs/3.1/colorutils_8h_source.html
  57. */
  58.  
  59. fill_gradient(leds,
  60. start_pixel,
  61. start_hue,
  62. end_pixel,
  63. end_hue,
  64. LONGEST_HUES);
  65.  
  66. showAnalogRGB( leds);
  67.  
  68. delay(1000);
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment