Guest User

Multiple_LEDS

a guest
Jun 6th, 2016
505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.91 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 11   // Specify length of each strip
  6. #define NUM_LEDS1 13
  7. #define NUM_LEDS2 17
  8. #define NUM_LEDS3 20
  9. #define NUM_LEDS4 21
  10. #define NUM_LEDS5 23
  11. #define TOTAL_LEDS 105
  12. #define BRIGHTNESS  20
  13. #define FRAMES_PER_SECOND  240
  14. #define COOLING  55
  15. #define SPARKING 120
  16. #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
  17. //etc.
  18.  
  19. CRGB leds[NUM_STRIPS][NUM_LEDS0 + NUM_LEDS1 + NUM_LEDS2 + NUM_LEDS3 + NUM_LEDS4 + NUM_LEDS5];  // Add all together here
  20.  
  21.  
  22. uint8_t stripLength;  // Used to store a strip length.
  23. uint8_t chanceOfGlitter = 80;
  24. bool gReverseDirection = false;
  25.  
  26. //---------------------------------------------------------------
  27. void setup() {
  28.   Serial.begin(115200);  // Allows serial monitor output (check baud rate)
  29.   delay(3000);
  30.   FastLED.addLeds<LED_TYPE, 6>(leds[0], NUM_LEDS0);  // Assign data pins
  31.   FastLED.addLeds<LED_TYPE, 9>(leds[1], NUM_LEDS1);
  32.   FastLED.addLeds<LED_TYPE, 10>(leds[2], NUM_LEDS2);
  33.   FastLED.addLeds<LED_TYPE, 11>(leds[3], NUM_LEDS3);
  34.   FastLED.addLeds<LED_TYPE, 12>(leds[4], NUM_LEDS4);
  35.   FastLED.addLeds<LED_TYPE, 13>(leds[5], NUM_LEDS5);
  36.   FastLED.setBrightness(  BRIGHTNESS );
  37. }
  38.  
  39. typedef void (*SimplePatternList[])();
  40. SimplePatternList gPatterns = {  sinelon, confetti, glitter, rainbow };
  41.  
  42. uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
  43. uint8_t gHue = 0; // rotating "base color" used by many of the patterns
  44.  
  45. //---------------------------------------------------------------
  46. void loop() {
  47. // Call the current pattern function once, updating the 'leds' array
  48.   gPatterns[gCurrentPatternNumber]();
  49.  
  50.   // send the 'leds' array out to the actual LED strip
  51.   FastLED.show();  
  52.   // insert a delay to keep the framerate modest
  53.   FastLED.delay(1000/FRAMES_PER_SECOND);
  54.  
  55.   // do some periodic updates
  56.   EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
  57.   EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically
  58.  
  59. }//end main loop
  60.  
  61. //-----function to return strip length-----
  62. uint8_t getStripLength(uint8_t stripNumber){
  63.   uint8_t L;
  64.   if (stripNumber == 0) { L = NUM_LEDS0; }
  65.   if (stripNumber == 1) { L = NUM_LEDS1; }
  66.   if (stripNumber == 2) { L = NUM_LEDS2; }
  67.   if (stripNumber == 3) { L = NUM_LEDS3; }
  68.   if (stripNumber == 4) { L = NUM_LEDS4; }
  69.   if (stripNumber == 5) { L = NUM_LEDS5; }
  70.   //etc.
  71.  
  72.   return L;
  73. }
  74.  
  75. void nextPattern()
  76. {
  77.   // add one to the current pattern number, and wrap around at the end
  78.   gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
  79. }
  80.  
  81. void confetti(void)
  82.  {
  83.  
  84.  // Gradiant filled with confetti
  85. for(uint8_t x = 0; x < NUM_STRIPS; x++) {
  86.     stripLength = getStripLength(x);
  87.     fill_gradient(leds[x], 0, CHSV(10,200,255), stripLength, CHSV(160,200,255), BACKWARD_HUES);
  88.     fadeToBlackBy(leds[x], stripLength,10);
  89.     int pos = random16(stripLength);
  90.     leds[x][pos]+= CHSV(gHue + random8(64),200,255);
  91.     delay(10);
  92.    }
  93.  }
  94.  
  95.  void glitter(void)
  96. {
  97. // Solid filled with Glitter
  98. for(uint8_t x = 0; x < NUM_STRIPS; x++) {
  99.     stripLength = getStripLength(x);
  100.     fill_solid( leds[x], stripLength, CRGB(0,50,255));
  101.     if (random8()<chanceOfGlitter)
  102.     {
  103.       leds[x][random16(stripLength)] += CRGB::White;
  104.      
  105.     }
  106. }
  107. }
  108.  
  109.  
  110. void rainbow(void)
  111. {
  112. for(uint8_t x = 0; x < NUM_STRIPS; x++) {
  113.     stripLength = getStripLength(x);
  114.     fill_rainbow( leds[x], stripLength, -1*millis()/2, 256/stripLength );
  115. }
  116. }
  117.  
  118.  
  119. void sinelon(void)
  120. {
  121. // Sinelon
  122. for(uint8_t x = 1; x < NUM_STRIPS; x++) {
  123.   stripLength = getStripLength(x);
  124.   fill_solid(leds[0], stripLength, CHSV( gHue, 255, 192));
  125.   fadeToBlackBy( leds[x], stripLength, 20);
  126.   int pos = beatsin16(50,0,stripLength);
  127.   leds[x][pos] += CHSV( gHue, 255, 192);
  128.  
  129. }
  130. }
  131.  
  132. void Fire2012()
  133. {
  134. for(uint8_t x = 0; x < NUM_STRIPS; x++) {
  135. // Array of temperature readings at each simulation cell
  136.    static byte heat[stripLength];
  137.  
  138.   // Step 1.  Cool down every cell a little
  139.     for( int i = 0; i < stripLength; i++) {
  140.       heat[x][i] = qsub8( heat[x][i],  random8(0, ((COOLING * 10) / stripLength) + 2));
  141.     }
  142.  
  143.     // Step 2.  Heat from each cell drifts 'up' and diffuses a little
  144.     for( int k= stripLength - 1; k >= 2; k--) {
  145.       heat[x][k] = (heat[x][k - 1] + heat[x][k - 2] + heat[x][k - 2] ) / 3;
  146.     }
  147.    
  148.     // Step 3.  Randomly ignite new 'sparks' of heat near the bottom
  149.     if( random8() < SPARKING ) {
  150.       int y = random8(7);
  151.       heat[x][y] = qadd8( heat[x][y], random8(160,255) );
  152.     }
  153.  
  154.     // Step 4.  Map from heat cells to LED colors
  155.     for( int j = 0; j < stripLength; j++) {
  156.       CRGB color = HeatColor( heat[x][j]);
  157.       int pixelnumber;
  158.       if( gReverseDirection ) {
  159.         pixelnumber = (stripLength-1) - j;
  160.       } else {
  161.         pixelnumber = j;
  162.       }
  163.       leds[x][pixelnumber] = color;
  164.     }
  165. }
  166. }
Advertisement
Add Comment
Please, Sign In to add comment