Advertisement
MoBacon2400

FastLED Multiple Strips

Aug 2nd, 2021
987
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.70 KB | None | 0 0
  1. //***************************************************************
  2. // The main code here was created by Mark Miller, Jan 2019
  3. // Modified By MoBacon2400 Aug. 2021 to run on multiple strips
  4. // Each strip can be modified separately for different effects, color, speed and number of LEDs per strip.
  5.  
  6. #include "FastLED.h" // FastLED library.
  7.  
  8. #define NUM_LED_STRIP_1 16
  9. #define NUM_LED_STRIP_2 16
  10. #define NUM_LED_STRIP_3 16
  11. #define NUM_LEDS_TOTAL 48
  12. //#define BRIGHTNESS 125
  13. #define LED_PIN_A 8
  14. #define LED_PIN_B 6
  15. #define LED_PIN_C 4
  16. #define LED_TYPE WS2812B
  17. //#define MASTER_BRIGHTNESS 160
  18. CRGB ledsA[NUM_LED_STRIP_1];
  19. CRGB ledsB[NUM_LED_STRIP_2];
  20. CRGB ledsC[NUM_LED_STRIP_3];
  21.  
  22. uint8_t max_bright = 255;
  23. //Strip 1----------------------------------------------------------------
  24. // Set initial start position of each color
  25. int16_t positionA1 = NUM_LED_STRIP_1*2/3;
  26. int16_t positionB1 = NUM_LED_STRIP_1/3;
  27. int16_t positionC1 = 0;
  28.  
  29. const uint16_t holdTimeX = 100; // Adjusts speed of travel
  30. int8_t delta1 = 1; // 1 or -1. Sets travel direction
  31.  
  32. //Strip 2----------------------------------------------------------------
  33. // Set initial start position of each color
  34. int16_t positionA2 = NUM_LED_STRIP_2*2/3;
  35. int16_t positionB2 = NUM_LED_STRIP_2/3;
  36. int16_t positionC2 = 0;
  37.  
  38. const uint16_t holdTimeY = 80; // Adjusts speed of travel
  39. int8_t delta2 = -1; // 1 or -1. Sets travel direction
  40.  
  41. //Strip 3--------------------------------------------------------------------
  42. // Set initial start position of each color
  43. int16_t positionA3 = NUM_LED_STRIP_3*2/4;
  44. int16_t positionB3 = NUM_LED_STRIP_3/3;
  45. int16_t positionC3 = 0;
  46.  
  47. const uint16_t holdTimeZ = 120; // Adjusts speed of travel
  48. int8_t delta3 = 1; // 1 or -1. Sets travel direction
  49.  
  50.  
  51. //---------------------------------------------------------------
  52. void setup() {
  53. delay( 3000 ); // power-up safety delay
  54. FastLED.addLeds<LED_TYPE, LED_PIN_A, GRB>(ledsA, NUM_LED_STRIP_1);
  55. FastLED.addLeds<LED_TYPE, LED_PIN_B, GRB>(ledsB, NUM_LED_STRIP_2);
  56. FastLED.addLeds<LED_TYPE, LED_PIN_C, GRB>(ledsC, NUM_LED_STRIP_3);
  57. FastLED.setBrightness(max_bright);
  58. }
  59.  
  60.  
  61.  
  62. //---------------------------------------------------------------
  63. void loop() {
  64.  
  65. EVERY_N_MILLISECONDS(holdTimeX) {
  66. strip_1();
  67. }
  68.  
  69. EVERY_N_MILLISECONDS(holdTimeY) {
  70. strip_2();
  71. }
  72.  
  73. EVERY_N_MILLISECONDS(holdTimeZ) {
  74. strip_3();
  75. }
  76.  
  77. FastLED.show(); // Show the pixels
  78. }
  79. //-----------------------------------------------------------------------
  80.  
  81. void strip_1(){
  82. // Fading tail effect. Comment out for solid colors
  83. fadeToBlackBy( ledsA, NUM_LED_STRIP_1, 200);
  84.  
  85. // assign pixel colors
  86. ledsA[positionA1] = CRGB::Purple;
  87. ledsA[positionB1] = CRGB::Gray; // Using grey so not as bright
  88. ledsA[positionC1] = CRGB::Navy;
  89.  
  90. // FastLED.show(); // Show the pixels
  91.  
  92. // Advance position based on delta, and rollover if needed.
  93. positionA1 = ((positionA1 + delta1 + NUM_LED_STRIP_1) % NUM_LED_STRIP_1);
  94. positionB1 = ((positionB1 + delta1 + NUM_LED_STRIP_1) % NUM_LED_STRIP_1);
  95. positionC1 = ((positionC1 + delta1 + NUM_LED_STRIP_1) % NUM_LED_STRIP_1);
  96.  
  97. }//end every_n
  98. //----------------------------------------------------------------------------------
  99. void strip_2(){
  100. // Fading tail effect. Comment out for solid colors
  101. fadeToBlackBy( ledsB, NUM_LED_STRIP_2, 100);
  102.  
  103. // assign pixel colors
  104. ledsB[positionA2] = CRGB::Cyan;
  105. ledsB[positionB2] = CRGB::Gray; // Using grey so not as bright
  106. ledsB[positionC2] = CRGB::Orange;
  107.  
  108. // FastLED.show(); // Show the pixels
  109.  
  110. // Advance position based on delta, and rollover if needed.
  111. positionA2 = ((positionA2 + delta2 + NUM_LED_STRIP_2) % NUM_LED_STRIP_2);
  112. positionB2 = ((positionB2 + delta2 + NUM_LED_STRIP_2) % NUM_LED_STRIP_2);
  113. positionC2 = ((positionC2 + delta2 + NUM_LED_STRIP_2) % NUM_LED_STRIP_2);
  114.  
  115. }//end every_n
  116. //-------------------------------------------------------------------------------------
  117. void strip_3(){
  118. // Fading tail effect. Comment out for solid colors
  119. fadeToBlackBy( ledsC, NUM_LED_STRIP_3, 220);
  120.  
  121. // assign pixel colors
  122. ledsC[positionA3] = CRGB::Blue;
  123. ledsC[positionB3] = CRGB::Gray; // Using grey so not as bright
  124. ledsC[positionC3] = CRGB::Red;
  125.  
  126. // FastLED.show(); // Show the pixels
  127.  
  128. // Advance position based on delta, and rollover if needed.
  129. positionA3 = ((positionA3 + delta3 + NUM_LED_STRIP_3) % NUM_LED_STRIP_3);
  130. positionB3 = ((positionB3 + delta3 + NUM_LED_STRIP_3) % NUM_LED_STRIP_3);
  131. positionC3 = ((positionC3 + delta3 + NUM_LED_STRIP_3) % NUM_LED_STRIP_3);
  132.  
  133. }//end every_n
  134.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement