AInterestingUser

BurningManPylons

Aug 20th, 2019
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.29 KB | None | 0 0
  1. #include <FastLED.h>
  2.  
  3. #define COLOR_ORDER BRG
  4. #define NUM_LEDS_PER_STRIP 60
  5.  
  6. #define FRAMES_PER_SECOND 60
  7.  
  8. #define MAX_BRIGHTNESS 164 // Thats full on, watch the power!
  9. #define MIN_BRIGHTNESS 32 // set to a minimum of 25%
  10.  
  11. const int FunctionPin = A0; // The Analog input pin to control program selection
  12. const int InPin1 = A1; // Analog to change variable in programs
  13. const int InPin2 = A2; // Analog to change variable in programs
  14. const int InPin3 = A3; // Analog to change variable in programs
  15.  
  16. bool gReverseDirection = false;
  17.  
  18. CRGB leds[NUM_LEDS_PER_STRIP];
  19.  
  20. void setup() {
  21.  
  22. // Pylon one
  23. FastLED.addLeds<APA102, 2, 3, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
  24.  
  25. FastLED.addLeds<APA102, 4, 5, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
  26.  
  27. FastLED.addLeds<APA102, 6, 7, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
  28.  
  29. //Pylon Two
  30. FastLED.addLeds<APA102, 8, 9, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
  31.  
  32. FastLED.addLeds<APA102, 10, 11, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
  33.  
  34. FastLED.addLeds<APA102, 12, 13, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
  35.  
  36. // Pylon Three
  37. FastLED.addLeds<APA102, 14, 15, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
  38.  
  39. FastLED.addLeds<APA102, 16, 17, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
  40.  
  41. FastLED.addLeds<APA102, 18, 19, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
  42.  
  43. //Pylon Four
  44. FastLED.addLeds<APA102, 20, 21, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
  45.  
  46. FastLED.addLeds<APA102, 22, 23, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
  47.  
  48. FastLED.addLeds<APA102, 24, 25, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
  49.  
  50. //Pylon Five
  51. FastLED.addLeds<APA102, 26, 27, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
  52.  
  53. FastLED.addLeds<APA102, 28, 29, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
  54.  
  55. FastLED.addLeds<APA102, 30, 31, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
  56.  
  57. //Pylon Six
  58. FastLED.addLeds<APA102, 32, 33, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
  59.  
  60. FastLED.addLeds<APA102, 34, 35, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
  61.  
  62. FastLED.addLeds<APA102, 36, 37, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
  63.  
  64.  
  65. delay(3000); // sanity delay
  66.  
  67.  
  68. }
  69.  
  70.  
  71.  
  72. int gCurrentPatternNum = map(analogRead(FunctionPin), 0, 1023, 0, 3); // problem area, honestly, throwing things at the wall
  73. // to see what sticks.
  74. typedef void (*PatternList[])(); // looked at other code, tried to emulate it
  75. PatternList gPatterns = {FirePattern, RainbowGlitter, juggle, sinelon};// however once code runs it seems like pot is no
  76. // longer read and I cant change values
  77. // uint8_t gCurrentPatternNum = 0; // used to select the pattern
  78. uint8_t gHue = 0;
  79.  
  80. void loop () {
  81.  
  82. gPatterns[gCurrentPatternNum]();
  83. FastLED.show();
  84. FastLED.delay(1000/FRAMES_PER_SECOND);
  85.  
  86.  
  87.  
  88. }
  89.  
  90. void sinelon()
  91. {
  92. // a colored dot sweeping back and forth, with fading trails
  93. fadeToBlackBy( leds, NUM_LEDS_PER_STRIP, 20);
  94. int pos = beatsin16( 13, 0, NUM_LEDS_PER_STRIP-1 );
  95. leds[pos] += CHSV( gHue, 255, 192);
  96. }
  97.  
  98. void juggle() {
  99. // eight colored dots, weaving in and out of sync with each other
  100. fadeToBlackBy( leds, NUM_LEDS_PER_STRIP, 20);
  101. byte dothue = 0;
  102. for( int i = 0; i < 8; i++) {
  103. leds[beatsin16( i+7, 0, NUM_LEDS_PER_STRIP-1 )] |= CHSV(dothue, 200, 255);
  104. dothue += 32;
  105. }
  106. }
  107. void RainbowGlitter ()
  108. {
  109.  
  110. int GlitterPop = map(analogRead(InPin1), 0, 1023, 20, 100);
  111. // FastLED's built-in rainbow generator
  112. fill_rainbow( leds, NUM_LEDS_PER_STRIP, gHue, 7);// put your main code here, to run repeatedly:
  113. addGlitter(GlitterPop);
  114.  
  115. }
  116. void FirePattern()
  117. {
  118. // Array of temperature readings at each simulation cell
  119.  
  120. static byte heat[NUM_LEDS_PER_STRIP];
  121.  
  122.  
  123. int COOLING = map(analogRead(InPin1), 0, 1023, 20, 100);
  124. int SPARKING = map(analogRead(InPin2), 0, 1023, 50, 100);
  125.  
  126. // Step 1. Cool down every cell a little
  127. for( int i = 0; i < NUM_LEDS_PER_STRIP; i++) {
  128. heat[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / NUM_LEDS_PER_STRIP) + 2));
  129. }
  130.  
  131. // Step 2. Heat from each cell drifts 'up' and diffuses a little
  132. for( int k= NUM_LEDS_PER_STRIP - 1; k >= 2; k--) {
  133. heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
  134. }
  135.  
  136. // Step 3. Randomly ignite new 'sparks' of heat near the bottom
  137. if( random8() < SPARKING ) {
  138. int y = random8(7);
  139. heat[y] = qadd8( heat[y], random8(160,255) );
  140. }
  141.  
  142. // Step 4. Map from heat cells to LED colors
  143. for( int j = 0; j < NUM_LEDS_PER_STRIP; j++) {
  144. CRGB color = HeatColor( heat[j]);
  145. int pixelnumber;
  146. if( gReverseDirection ) {
  147. pixelnumber = (NUM_LEDS_PER_STRIP-1) - j;
  148. } else {
  149. pixelnumber = j;
  150. }
  151. leds[pixelnumber] = color;
  152. }
  153. }
  154.  
  155.  
  156. void addGlitter( fract8 chanceOfGlitter)
  157. {
  158. if( random8() < chanceOfGlitter) {
  159. leds[ random16(NUM_LEDS_PER_STRIP) ] += CRGB::White;
  160. }
  161. }
Advertisement
Add Comment
Please, Sign In to add comment