MoBacon2400

FastLED_Bounce

Aug 19th, 2021
826
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.32 KB | None | 0 0
  1. // This code was created from multiple sources but partially based on:
  2. // Matrix
  3. //By: funkboxing LED
  4. //Modified by: Andrew Tuling //Date: Oct, 2014
  5.  
  6. #include "FastLED.h" // FastLED library.
  7.  
  8. #define NUM_LED_STRIP_1 37
  9. #define NUM_LED_STRIP_2 37 //Led Strips can be of differant lengths
  10. #define NUM_LED_STRIP_3 27
  11. #define NUM_LEDS_TOTAL 74
  12. #define BRIGHTNESS 125
  13. #define LED_PIN_A 6
  14. #define LED_PIN_B 4 // Choose a pin for each strip
  15. #define LED_PIN_C 8
  16. #define UPDATES_PER_SECOND 50 // Set Speed
  17. #define LED_TYPE WS2812B
  18.  
  19. CRGB ledsA[NUM_LED_STRIP_1];
  20. CRGB ledsB[NUM_LED_STRIP_2];
  21. CRGB ledsC[NUM_LED_STRIP_3];
  22.  
  23. uint8_t max_bright = 200;
  24.  
  25. //Settings for Strip A "bounce" variables for this Segment ////////////////////////////////////////////////
  26. int thisdelay = 120; // A delay value for sequence(A)
  27. int thishue = 95; //Starting Color
  28. int thissat = 255;
  29. int thisdir = 0;
  30. bool huerot = 1; // Does the hue rotate? 1 = yes, 0= single color
  31. uint8_t bgclr = 0;
  32. uint8_t bgbri = 0;
  33. //Settings for Strip B "text" variables for this Segment ///////////////////////////////////////////////////
  34. int thisdelay2 = 100; // A delay value for sequence(B)
  35. int thishue2 = 8; //Starting Color
  36. int thissat2 = 200;
  37. int thisdir2 = 0;
  38. bool huerot2 = 1; // Does the hue rotate? 1 = yes, 0= single color
  39. uint8_t bgclr2 = 0;
  40. uint8_t bgbri2 = 0;
  41. //Settings for Strip C "logo" variables for this Segment//////////////////////////////////////////////////////
  42. int thisdelay3 = 40; // A delay value for sequence(C)
  43. int thishue3 = 0; //Starting Color
  44. int thissat3 = 100;
  45. int thisdir3 = 0;
  46. bool huerot3 = 0; // Does the hue rotate? 1 = yes, 0= single color
  47. uint8_t bgclr3 = 30;
  48. uint8_t bgbri3 = 50;
  49.  
  50. void setup() { //////////////////////////////////////////////////////////////////////////////////////////////////
  51. delay( 3000 ); // power-up safety delay
  52. FastLED.addLeds<LED_TYPE, LED_PIN_A, GRB>(ledsA, NUM_LED_STRIP_1);
  53. FastLED.addLeds<LED_TYPE, LED_PIN_B, GRB>(ledsB, NUM_LED_STRIP_2);
  54. FastLED.addLeds<LED_TYPE, LED_PIN_C, GRB>(ledsC, NUM_LED_STRIP_3);
  55. FastLED.setBrightness(max_bright);
  56. }
  57.  
  58. void loop () { /////////////////////////////////////////////////////////////////////////////////////////////////////
  59.  
  60. EVERY_N_MILLISECONDS(thisdelay) { // FastLED based non-blocking delay to update/display the sequence.
  61. bounce(); // bounce section = ledsA Strip 1.
  62. }
  63.  
  64. EVERY_N_MILLISECONDS(thisdelay2 ) { // FastLED based non-blocking delay to update/display the sequence.
  65. text(); // text section = ledsB, Strip 2.
  66. }
  67.  
  68. EVERY_N_MILLISECONDS(thisdelay3 ) { // FastLED based non-blocking delay to update/display the sequence.
  69. logo(); // logo section = ledsC, Strip 3.
  70. }
  71.  
  72. FastLED.show();
  73. } // loop()
  74.  
  75. void bounce() { ////////////////////////////////////////////////////////////////////////////////////////////////
  76.  
  77. if (huerot) thishue=thishue-5;
  78.  
  79. if (random16(80) > 72) {
  80. if (thisdir == 0) ledsA[0] = CHSV(thishue, thissat, 255);
  81. else ledsB[NUM_LED_STRIP_1-1] = CHSV(thishue, thissat, 255);
  82. }
  83. else {
  84. if (thisdir == 0) ledsA[0] = CHSV(bgclr, thissat, bgbri);
  85. else ledsB[NUM_LED_STRIP_1-1] = CHSV(bgclr, thissat, bgbri);
  86. }
  87. if (thisdir == 0) {
  88. for (int i = NUM_LED_STRIP_1-1; i >0 ; i-- ) ledsA[i] = ledsA[i-1];
  89. } else {
  90. for (int i = 0; i < NUM_LED_STRIP_1-1 ; i++ ) ledsA[i] = ledsA[i+1];
  91. }
  92. }
  93.  
  94. void text() { ///////////////////////////////////////////////////////////////////////////////////////////////////////
  95.  
  96. if (huerot2) thishue2=thishue2-1;
  97.  
  98. if (random8(80) > 70) {
  99. if (thisdir2 == 0) ledsB[0] = CHSV(thishue2, thissat2, 255);
  100. else ledsB[NUM_LED_STRIP_2-1] = CHSV(thishue2, thissat2, 255);
  101. }
  102. // else {
  103. //if (thisdir2 == 0) ledsB[0] = CHSV(bgclr2, thissat2, bgbri2);
  104. //else ledsB[NUM_LED_STRIP_2-1] = CHSV(bgclr2, thissat2, bgbri2);
  105. // }
  106. if (thisdir2 == 0) {
  107. for (int i = NUM_LED_STRIP_2-1; i >0 ; i-- ) ledsB[i] = ledsB[i-1];
  108. } else {
  109. for (int i = 0; i < NUM_LED_STRIP_2-1 ; i++ ) ledsB[i] = ledsB[i+1];
  110. }
  111. }
  112.  
  113. void logo() { ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  114.  
  115.  
  116. if (huerot3) thishue3=thishue3-1;
  117.  
  118. if (random16(80) > 70) {
  119. if (thisdir3 == 0) ledsC[0] = CHSV(thishue3, thissat3, 255);
  120. else ledsC[NUM_LED_STRIP_3-1] = CHSV(thishue3, thissat3, 255);
  121. }
  122. else {
  123. if (thisdir3 == 0) ledsC[0] = CHSV(bgclr3, thissat3, bgbri3);
  124. else ledsC[NUM_LED_STRIP_3-1] = CHSV(bgclr3, thissat3, bgbri3);
  125. }
  126. if (thisdir3 == 0) {
  127. for (int i = NUM_LED_STRIP_3-1; i >0 ; i-- ) ledsC[i] = ledsC[i-1];
  128. } else {
  129. for (int i = 0; i < NUM_LED_STRIP_3-1 ; i++ ) ledsC[i] = ledsC[i+1];
  130. }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment