Guest User

Untitled

a guest
Oct 19th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. #include "FastLED.h"
  2.  
  3. FASTLED_USING_NAMESPACE
  4.  
  5. // FastLED "100-lines-of-code" demo reel, showing just a few
  6. // of the kinds of animation patterns you can quickly and easily
  7. // compose using FastLED.
  8. //
  9. // This example also shows one easy way to define multiple
  10. // animations patterns and have them automatically rotate.
  11. //
  12. // -Mark Kriegsman, December 2014
  13.  
  14. #if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000)
  15. #warning "Requires FastLED 3.1 or later; check github for latest code."
  16. #endif
  17.  
  18. #define DATA_PIN 3
  19. //#define CLK_PIN 4
  20. #define LED_TYPE WS2811
  21. #define COLOR_ORDER GRB
  22. #define NUM_LEDS 64
  23. CRGB leds[NUM_LEDS];
  24.  
  25. #define BRIGHTNESS 96
  26. #define FRAMES_PER_SECOND 120
  27.  
  28. void setup() {
  29. delay(3000); // 3 second delay for recovery
  30.  
  31. // tell FastLED about the LED strip configuration
  32. FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  33. //FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  34.  
  35. // set master brightness control
  36. FastLED.setBrightness(BRIGHTNESS);
  37. }
  38.  
  39.  
  40. // List of patterns to cycle through. Each is defined as a separate function below.
  41. typedef void (*SimplePatternList[])();
  42. SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm };
  43.  
  44. uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
  45. uint8_t gHue = 0; // rotating "base color" used by many of the patterns
  46.  
  47. void loop()
  48. {
  49. // Call the current pattern function once, updating the 'leds' array
  50. gPatterns[gCurrentPatternNumber]();
  51.  
  52. // send the 'leds' array out to the actual LED strip
  53. FastLED.show();
  54. // insert a delay to keep the framerate modest
  55. FastLED.delay(1000/FRAMES_PER_SECOND);
  56.  
  57. // do some periodic updates
  58. EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
  59. EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically
  60. }
  61.  
  62. #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
  63.  
  64. void nextPattern()
  65. {
  66. // add one to the current pattern number, and wrap around at the end
  67. gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
  68. }
  69.  
  70. void rainbow()
  71. {
  72. // FastLED's built-in rainbow generator
  73. fill_rainbow( leds, NUM_LEDS, gHue, 7);
  74. }
  75.  
  76. void rainbowWithGlitter()
  77. {
  78. // built-in FastLED rainbow, plus some random sparkly glitter
  79. rainbow();
  80. addGlitter(80);
  81. }
  82.  
  83. void addGlitter( fract8 chanceOfGlitter)
  84. {
  85. if( random8() < chanceOfGlitter) {
  86. leds[ random16(NUM_LEDS) ] += CRGB::White;
  87. }
  88. }
  89.  
  90. void confetti()
  91. {
  92. // random colored speckles that blink in and fade smoothly
  93. fadeToBlackBy( leds, NUM_LEDS, 10);
  94. int pos = random16(NUM_LEDS);
  95. leds[pos] += CHSV( gHue + random8(64), 200, 255);
  96. }
  97.  
  98. void sinelon()
  99. {
  100. // a colored dot sweeping back and forth, with fading trails
  101. fadeToBlackBy( leds, NUM_LEDS, 20);
  102. int pos = beatsin16( 13, 0, NUM_LEDS-1 );
  103. leds[pos] += CHSV( gHue, 255, 192);
  104. }
  105.  
  106. void bpm()
  107. {
  108. // colored stripes pulsing at a defined Beats-Per-Minute (BPM)
  109. uint8_t BeatsPerMinute = 62;
  110. CRGBPalette16 palette = PartyColors_p;
  111. uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
  112. for( int i = 0; i < NUM_LEDS; i++) { //9948
  113. leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
  114. }
  115. }
  116.  
  117. void juggle() {
  118. // eight colored dots, weaving in and out of sync with each other
  119. fadeToBlackBy( leds, NUM_LEDS, 20);
  120. byte dothue = 0;
  121. for( int i = 0; i < 8; i++) {
  122. leds[beatsin16( i+7, 0, NUM_LEDS-1 )] |= CHSV(dothue, 200, 255);
  123. dothue += 32;
  124. }
  125. }
Add Comment
Please, Sign In to add comment