Guest User

modified multi-strip multi-pattern

a guest
Jun 10th, 2016
205
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. #define LED_TYPE NEOPIXEL
  3. #define NUM_STRIPS 6 // Total number of strips
  4.  
  5. #define NUM_LEDS0 16 // Specify length of each strip
  6. #define NUM_LEDS1 21
  7. #define NUM_LEDS2 32
  8. #define BRIGHTNESS 20
  9. #define FRAMES_PER_SECOND 120
  10. #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
  11. //etc.
  12.  
  13. CRGB leds[NUM_STRIPS][NUM_LEDS0 + NUM_LEDS1 + NUM_LEDS2]; // Add all together here
  14.  
  15.  
  16. uint8_t stripLength; // Used to store a strip length.
  17. uint8_t chanceOfGlitter = 80;
  18. bool gReverseDirection = false;
  19.  
  20. //---------------------------------------------------------------
  21. void setup() {
  22. Serial.begin(115200); // Allows serial monitor output (check baud rate)
  23. delay(3000);
  24. FastLED.addLeds<LED_TYPE, 3>(leds[0], NUM_LEDS0); // Assign data pins
  25. FastLED.addLeds<LED_TYPE, 9>(leds[1], NUM_LEDS1);
  26. FastLED.addLeds<LED_TYPE, 6>(leds[2], NUM_LEDS2);
  27. FastLED.setBrightness( BRIGHTNESS );
  28. }
  29.  
  30. typedef void (*SimplePatternList[])();
  31. SimplePatternList gPatterns = { sinelon };
  32.  
  33. uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
  34. uint8_t gHue = 0; // rotating "base color" used by many of the patterns
  35.  
  36. //---------------------------------------------------------------
  37. void loop() {
  38. // Call the current pattern function once, updating the 'leds' array
  39. gPatterns[gCurrentPatternNumber]();
  40.  
  41. // send the 'leds' array out to the actual LED strip
  42. FastLED.show();
  43. // insert a delay to keep the framerate modest
  44. FastLED.delay(1000/FRAMES_PER_SECOND);
  45.  
  46. // do some periodic updates
  47. EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
  48. EVERY_N_SECONDS( 20 ) { nextPattern(); } // change patterns periodically
  49.  
  50. }//end main loop
  51.  
  52. //-----function to return strip length-----
  53. uint8_t getStripLength(uint8_t stripNumber){
  54. uint8_t L;
  55. if (stripNumber == 0) { L = NUM_LEDS0; }
  56. if (stripNumber == 1) { L = NUM_LEDS1; }
  57. if (stripNumber == 2) { L = NUM_LEDS2; }
  58. return L;
  59. }
  60.  
  61. void nextPattern()
  62. {
  63. // add one to the current pattern number, and wrap around at the end
  64. gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
  65. }
  66.  
  67. //void confetti(void)
  68. // {
  69. //
  70. // // Gradiant filled with confetti
  71. //for(uint8_t x = 0; x < NUM_STRIPS; x++) {
  72. // static uint16_t stripLength = getStripLength(x);
  73. // fill_gradient(leds[x], 0, CHSV(10,200,255), stripLength, CHSV(160,200,255), BACKWARD_HUES);
  74. // fadeToBlackBy(leds[x], stripLength,10);
  75. // int pos = random16(stripLength);
  76. // leds[x][pos]+= CHSV(gHue + random8(64),200,255);
  77. // delay(10);
  78. // }
  79. // }
  80. //
  81. // void glitter(void)
  82. //{
  83. //// Solid filled with Glitter
  84. //for(uint8_t x = 0; x < NUM_STRIPS; x++) {
  85. // static uint16_t stripLength = getStripLength(x);
  86. // fill_solid( leds[x], stripLength, CRGB(0,50,255));
  87. // if (random8()<chanceOfGlitter)
  88. // {
  89. // leds[x][random16(stripLength)] += CRGB::White;
  90. //
  91. // }
  92. //}
  93. //}
  94. //
  95. //
  96. //void rainbow(void)
  97. //{
  98. //for(uint8_t x = 0; x < NUM_STRIPS; x++) {
  99. // static uint16_t stripLength = getStripLength(x);
  100. // fill_rainbow( leds[x], stripLength, -1*millis()/2, 256/stripLength );
  101. //}
  102. //}
  103.  
  104.  
  105. void sinelon(void)
  106. {
  107. // Sinelon
  108. for(uint8_t x = 0; x < NUM_STRIPS; x++) {
  109. static uint16_t stripLength = getStripLength(x);
  110. fill_solid(leds[0], stripLength, CHSV( gHue, 255, 192));
  111. fadeToBlackBy( leds[x], stripLength, 20);
  112. int pos = beatsin16(10,0,stripLength);
  113. leds[x][pos] += CHSV( gHue, 255, 192);
  114.  
  115. }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment