Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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    2
  19. #define DATA_PIN_2  5
  20. #define LED_TYPE    WS2812B
  21. #define COLOR_ORDER GRB
  22.  
  23. #define NUM_STRIPS 2
  24. #define NUM_LEDS_STRIP_1 75
  25. #define NUM_LEDS_STRIP_2 194
  26. #define NUM_LEDS NUM_LEDS_STRIP_1 + NUM_LEDS_STRIP_2
  27.  
  28. CRGB leds[NUM_LEDS];
  29.  
  30. #define BRIGHTNESS          92
  31. #define FRAMES_PER_SECOND  120
  32.  
  33. void setup() {
  34.   delay(3000); // 3 second delay for recovery
  35.  
  36.   // tell FastLED about the LED strip configuration
  37.   FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, 0, NUM_LEDS_STRIP_1).setCorrection(TypicalLEDStrip);
  38.   FastLED.addLeds<LED_TYPE,DATA_PIN_2,COLOR_ORDER>(leds, NUM_LEDS_STRIP_1, NUM_LEDS_STRIP_2).setCorrection(TypicalLEDStrip);  
  39.  
  40.   // set master brightness control
  41.   FastLED.setBrightness(BRIGHTNESS);
  42. }
  43.  
  44.  
  45. // List of patterns to cycle through.  Each is defined as a separate function below.
  46. typedef void (*SimplePatternList[])();
  47. SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, solid, juggle2, confetti, sinelon, juggle, bpm, sinelonWithGlitter, bpmWithGlitter, juggle3 };
  48.  
  49. uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
  50. uint8_t gHue = 0; // rotating "base color" used by many of the patterns
  51.  
  52. void loop()
  53. {
  54.   // Call the current pattern function once, updating the 'leds' array
  55.   gPatterns[gCurrentPatternNumber]();
  56.  
  57.   // send the 'leds' array out to the actual LED strip
  58.   FastLED.show();  
  59.   // insert a delay to keep the framerate modest
  60.   FastLED.delay(1000/FRAMES_PER_SECOND);
  61.  
  62.   // do some periodic updates
  63.   EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
  64.   EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically
  65. }
  66.  
  67. #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
  68.  
  69. void nextPattern()
  70. {
  71.   // add one to the current pattern number, and wrap around at the end
  72.   gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
  73. }
  74.  
  75. void rainbow()
  76. {
  77.   // FastLED's built-in rainbow generator
  78.   fill_rainbow( leds, NUM_LEDS, gHue, 7);
  79. }
  80.  
  81. void rainbowWithGlitter()
  82. {
  83.   // built-in FastLED rainbow, plus some random sparkly glitter
  84.   rainbow();
  85.   addGlitter(80);
  86. }
  87.  
  88. void addGlitter( fract8 chanceOfGlitter)
  89. {
  90.   if( random8() < chanceOfGlitter) {
  91.     leds[ random16(NUM_LEDS) ] += CRGB::White;
  92.   }
  93. }
  94.  
  95. void confetti()
  96. {
  97.   // random colored speckles that blink in and fade smoothly
  98.   fadeToBlackBy( leds, NUM_LEDS, 10);
  99.   int pos = random16(NUM_LEDS);
  100.   leds[pos] += CHSV( gHue + random8(64), 200, 255);
  101. }
  102.  
  103. void sinelon()
  104. {
  105.   // a colored dot sweeping back and forth, with fading trails
  106.   fadeToBlackBy( leds, NUM_LEDS, 20);
  107.   int pos = beatsin16( 13, 0, NUM_LEDS-1 );
  108.   leds[pos] += CHSV( gHue, 255, 192);
  109. }
  110.  
  111. void sinelonWithGlitter()
  112. {
  113.   sinelon();
  114.   addGlitter(80);
  115. }
  116.  
  117. void bpm()
  118. {
  119.   // colored stripes pulsing at a defined Beats-Per-Minute (BPM)
  120.   uint8_t BeatsPerMinute = 62;
  121.   CRGBPalette16 palette = PartyColors_p;
  122.   uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
  123.   for( int i = 0; i < NUM_LEDS; i++) { //9948
  124.     leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
  125.   }
  126. }
  127.  
  128. void solid() {
  129.   fill_solid( leds, NUM_LEDS, gHue);
  130. }
  131.  
  132. void bpmWithGlitter()
  133. {
  134.   bpm();
  135.   addGlitter(80);
  136. }
  137.  
  138. void juggle() {
  139.   juggle(8);
  140. }
  141.  
  142. void juggle2() {
  143.   juggle(2);
  144. }
  145.  
  146. void juggle3() {
  147.   juggle(5);
  148. }
  149.  
  150. void juggle(int count_leds) {
  151.   // eight colored dots, weaving in and out of sync with each other
  152.   fadeToBlackBy( leds, NUM_LEDS, 20);
  153.   byte dothue = 0;
  154.   for( int i = 0; i < count_leds; i++) {
  155.     leds[beatsin16( i+count_leds-1, 0, NUM_LEDS-1 )] |= CHSV(dothue, 200, 255);
  156.     dothue += 32;
  157.   }
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement