Advertisement
TopHatRaver

Anjunabeach

Jun 12th, 2018
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 12.66 KB | None | 0 0
  1. // Marc Miller, Oct 2017
  2.  
  3. #include "FastLED.h"
  4. #define NUM_LEDS 10        //216
  5. #define NUM_LEDS_REAL 10  //192
  6. #define DATA_PIN 17 //5
  7. #define LED_TYPE WS2811
  8. #define COLOR_ORDER GRB
  9. #define STRIP_EVEN 14
  10. #define STRIP_ODD 10
  11.  
  12. #define BRIGHTNESS          96
  13. #define FRAMES_PER_SECOND  120
  14. #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
  15. #define UPDATES_PER_SECOND 1000
  16.  
  17. uint8_t I = 10, J=14;
  18. uint8_t START1 = 0, END1 = I-1;
  19. uint8_t START2 = START1+I, END2 = END1+J;
  20. uint8_t START3 = START2+J, END3 = END2+I;
  21. uint8_t START4 = START3+I, END4 = END3+J;
  22. uint8_t START5 = START4+J, END5 = END4+I;
  23. uint8_t START6 = START5+I, END6 = END5+J;
  24. uint8_t START7 = START6+J, END7 = END6+I;
  25. uint8_t START8 = START7+I, END8 = END7+J;
  26. uint8_t START9 = START8+J, END9 = END8+I;
  27. uint8_t START10 = START9+I, END10 = END9+J;
  28. uint8_t START11 = START10+J, END11 = END10+I;
  29. uint8_t START12 = START11+I, END12 = END11+J;
  30. uint8_t START13 = START12+J, END13 = END12+I;
  31. uint8_t START14 = START13+I, END14 = END13+J;
  32. uint8_t START15 = START14+J, END15 = END14+I;
  33. uint8_t START16 = START15+I, END16 = END15+J;
  34. uint8_t STARTO = START16+J, ENDO = END16+I;
  35. uint8_t STARTE = STARTO+I, ENDE = ENDO+J;
  36.  
  37. int MyDelay = 200;
  38. uint8_t spacer = 4;
  39. int MyColor = 0;
  40.  
  41. uint16_t holdTime = 300;  // Milliseconds to hold position before advancing.
  42. uint8_t spacing = 4;      // Sets pixel spacing. [Use 2 or greater]
  43. int8_t delta = 1;         // Sets forward or backwards direction amount. (Can be negative.)
  44. uint8_t width = 2;        // Can increase the number of pixels (width) of the chase. [1 or greater]
  45.  
  46. boolean fadingTail = 0;   // Add fading tail? [1=true, 0=false]
  47. uint8_t fadeRate = 150;   // How fast to fade out tail. [0-255]
  48.  
  49. uint8_t hue = 60;         // Starting color.
  50. uint8_t hue2_shift = 50;  // Hue shift for secondary color.  Use 0 for no shift. [0-255]
  51. boolean DEBUG = 1;        // Print some info to serial monitor. [1=true, 0=falue]
  52.  
  53. int16_t pos;              // Pixel position.
  54. int8_t advance;           // Stores the advance amount.
  55. uint8_t color;            // Stores a hue color.
  56.  
  57.  
  58. //CRGB leds[NUM_LEDS];  // Not using this.  Using CRGBArray instead.
  59.  
  60. CRGBArray<NUM_LEDS> leds;
  61.  
  62. CRGBSet part1(leds(START1,END1));  
  63. CRGBSet part2(leds(START2,END2));
  64. CRGBSet part3(leds(START3,END3));
  65. CRGBSet part4(leds(START4,END4));
  66. CRGBSet part5(leds(START5,END5));
  67. CRGBSet part6(leds(START6,END6));
  68. CRGBSet part7(leds(START7,END7));
  69. CRGBSet part8(leds(START8,END8));
  70. CRGBSet part9(leds(START9,END9));
  71. CRGBSet part10(leds(START10,END10));
  72. CRGBSet part11(leds(START11,END11));
  73. CRGBSet part12(leds(START12,END12));
  74. CRGBSet part13(leds(START13,END13));
  75. CRGBSet part14(leds(START14,END14));
  76. CRGBSet part15(leds(START15,END15));
  77. CRGBSet part16(leds(START16,END16));
  78. CRGBSet tempOdd(leds(STARTO,ENDO));
  79. CRGBSet tempEven(leds(STARTE,ENDE));
  80.  
  81. uint8_t counter = 0;
  82.  
  83. CRGBPalette16 currentPalette;
  84. TBlendType    currentBlending;
  85.  
  86. extern CRGBPalette16 Anjunabeach;
  87. extern const TProgmemPalette16 Anjunabeach_p PROGMEM;
  88.  
  89. //---------------------------------------------------------------
  90. void setup() {
  91.   delay(3000);
  92.   FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  93.   FastLED.setBrightness(50);
  94.      
  95.   currentPalette = Anjunabeach_p;
  96.   currentBlending = LINEARBLEND;
  97.   //Serial.begin(9600);
  98.  
  99. }
  100.  
  101. typedef void (*SimplePatternList[])();
  102.  
  103. SimplePatternList gPatterns = {
  104.                   Marquee
  105.                   /*SolidColors
  106.                   ,fillrainbow
  107.                   ,colorblocks
  108.                   ,allrainbow
  109.                   ,confetti
  110.                   ,singlerainbow
  111.                   ,swirl
  112.                   ,confetti
  113.                   ,swirlrainbow
  114.                   ,colorbars //need to fix
  115.                   //chasingdots //runs too slow
  116.                   ,PalletLoop
  117.                   ,sinelon*/
  118.                   };
  119.  
  120. uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
  121. uint8_t gHue = 0; // rotating "base color" used by many of the patterns
  122. //---------------------------------------------------------------
  123. void loop()
  124. {
  125.  
  126.   gPatterns[gCurrentPatternNumber]();
  127.  
  128.   FastLED.show();  
  129.  
  130.   FastLED.delay(1000/FRAMES_PER_SECOND);
  131.  
  132.   // do some periodic updates
  133.    
  134.   EVERY_N_SECONDS( 60 ) { nextPattern(); } // change patterns periodically
  135.  
  136.   }
  137.  
  138.  
  139. void fillrainbow()
  140. {
  141.   fill_rainbow(part2, STRIP_EVEN, millis()/20);
  142.   fill_solid(part1, STRIP_ODD, CHSV(138,255,255));
  143.   dupe();
  144. }
  145.  
  146. void allrainbow()
  147. {
  148.   fill_rainbow(part1, STRIP_ODD, millis()/20);
  149.   fill_rainbow(part2, STRIP_EVEN, millis()/20);
  150.   dupe();
  151. }
  152.  
  153. void singlerainbow()
  154. {
  155.   fill_rainbow(leds,NUM_LEDS_REAL,millis()/20);
  156.   FastLED.show();
  157. }
  158.  
  159. void colorblocks()
  160. {
  161.   int MyColor = (random16(0,255));
  162.   int MyHue = (random16(125,255));
  163.   fill_solid(part1, STRIP_ODD, CHSV(MyColor,255,255));
  164.   fill_solid(part2, STRIP_EVEN, CHSV((MyColor-125)%255,255,255));
  165.   dupe();
  166.   delay(500);
  167. }
  168.  
  169. void colorbars()
  170. {
  171.  
  172.   int MyColor = (random16(0,255));
  173.   fill_solid(tempEven, STRIP_EVEN,CHSV(MyColor,255,255)); //SET TEMP EVEN STRIP
  174.   fill_solid(tempOdd, STRIP_ODD, CHSV(MyColor,255,255)); //SET TEMP ODD STRIP
  175.  
  176.   part1 = tempOdd;
  177.   FastLED.show();
  178.   delay(MyDelay);
  179.  
  180.   part2 = tempEven;
  181.   FastLED.show();
  182.   delay(MyDelay);
  183.  
  184.   part3 = part1;
  185.   MyColor = (random16(0,255));
  186.   fill_solid(tempEven, STRIP_EVEN,CHSV(MyColor,255,255)); //SET TEMP EVEN STRIP
  187.   fill_solid(tempOdd, STRIP_ODD, CHSV(MyColor,255,255)); //SET TEMP ODD STRIP
  188.   part1 = tempOdd;
  189.   FastLED.show();
  190.   delay(MyDelay);
  191.  
  192.   part4 = part2;
  193.   part2 = tempEven;
  194.   FastLED.show();
  195.   delay(MyDelay);
  196.  
  197.   for (uint8_t x = 0; x<10; x++)
  198.   {
  199.   MyColor = (random16(0,255));
  200.   fill_solid(tempEven, STRIP_EVEN,CHSV(MyColor,255,255)); //SET TEMP EVEN STRIP
  201.   fill_solid(tempOdd, STRIP_ODD, CHSV(MyColor,255,255)); //SET TEMP ODD STRIP
  202.   part15 = part13;
  203.   part13 = part11;
  204.   part11 = part9;
  205.   part9 = part7;
  206.   part7 = part5;
  207.   part5 = part3;
  208.   part3 = part1;
  209.   part1 = tempOdd;
  210.   FastLED.show();
  211.   delay(MyDelay);
  212.  
  213.   part16=part14;
  214.   part14 = part12;
  215.   part12 = part10;
  216.   part10 = part8;
  217.   part8 = part6;
  218.   part6 = part4;
  219.   part4 = part2;
  220.   part2 = tempEven;
  221.   FastLED.show();
  222.   delay(MyDelay);
  223.  
  224.   MyColor = (random16(0,255));
  225.   fill_solid(tempEven, STRIP_EVEN,CHSV(MyColor,255,255)); //SET TEMP EVEN STRIP
  226.   fill_solid(tempOdd, STRIP_ODD, CHSV(MyColor,255,255)); //SET TEMP ODD STRIP
  227.   part15 = part13;
  228.   part13 = part11;
  229.   part11 = part9;
  230.   part9 = part7;
  231.   part7 = part5;
  232.   part5 = part3;
  233.   part3 = part1;
  234.   part1 = tempOdd;
  235.   FastLED.show();
  236.   delay(MyDelay);
  237.  
  238.   part16=part14;
  239.   part14 = part12;
  240.   part12 = part10;
  241.   part10 = part8;
  242.   part8 = part6;
  243.   part6 = part4;
  244.   part4 = part2;
  245.  
  246.   part2 = tempEven;
  247.   FastLED.show();
  248.   delay(MyDelay);
  249.   }
  250.  
  251.  
  252.    
  253.    
  254. }
  255.  
  256. void dupe()
  257. {
  258.   part3 = part1;  //creates dupicate copy in second half of strip
  259.   part4 = part2;
  260.   part5 = part1;
  261.   part6 = part2;
  262.   part7 = part1;
  263.   part8 = part2;
  264.   part9 = part1;
  265.   part10 = part2;
  266.   part11 = part1;
  267.   part12 = part2;
  268.   part13 = part1;
  269.   part14 = part2;
  270.   part15 = part1;
  271.   part16 = part2;
  272.  
  273.   FastLED.show();
  274. }
  275.  
  276. void chasingdots()
  277. {
  278.   for(uint8_t x = NUM_LEDS_REAL -1; x>0; x--)
  279.   {
  280.     leds[x]=leds[x-1];
  281.     FastLED.show();
  282.   }
  283.  
  284. uint8_t R = random8(100);
  285. uint8_t c = (counter % spacer);
  286.  
  287. if (c==0)
  288.   {
  289.     leds[0] = CHSV(random16(128,235),random16(128,235),255);
  290.   }
  291.   else
  292.   {
  293.     leds[0] = CHSV(0,0,0);
  294.   }
  295. counter++;
  296.  
  297. }
  298.  
  299. void swirl()
  300. {
  301.   int MyColor = random16(0,255);
  302.   for(uint8_t loop = 0; loop<24; loop++)
  303.   {
  304.   for(uint8_t y = 23-loop; y<NUM_LEDS_REAL; y=y+24)
  305.     {
  306.      
  307.       leds[y] = CHSV(MyColor,255,255);
  308.       FastLED.show();
  309.      
  310.     }
  311.   }  
  312. }
  313.  
  314. void swirlrainbow()
  315. {
  316.   fill_solid(leds, NUM_LEDS_REAL, CRGB::Black);
  317.  
  318.   //uint8_t MyColor = 0;
  319.   for(uint8_t loop = 0; loop<24; loop++)
  320.   {
  321.     MyColor = MyColor + (255/24);
  322.    
  323.   for(uint8_t y = 23-loop; y<NUM_LEDS_REAL; y=y+24)
  324.     {
  325.      
  326.       leds[y] = CHSV(MyColor,255,255);
  327.       FastLED.show();
  328.      
  329.     }
  330.   }  
  331. }
  332.  
  333. void confetti()
  334. {
  335.   // random colored speckles that blink in and fade smoothly
  336.   fadeToBlackBy( leds, NUM_LEDS_REAL, 10);
  337.   int pos = random16(NUM_LEDS_REAL);
  338.   leds[pos] += CHSV( gHue + random16(255), 200, 255);
  339.   FastLED.show();
  340. }
  341.  
  342. void sinelon()
  343. {
  344.   // a colored dot sweeping back and forth, with fading trails
  345.   fadeToBlackBy( leds, NUM_LEDS_REAL, 1);
  346.   int pos = beatsin16( 5, 0, NUM_LEDS_REAL-1 );
  347.   leds[pos] += CHSV( gHue, 255, 255);
  348. }
  349.  
  350.  
  351. void nextPattern()
  352. {
  353.   // add one to the current pattern number, and wrap around at the end
  354.   gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
  355. }
  356.  
  357. const TProgmemPalette16 myAnjunaColors_p PROGMEM =
  358. {
  359.     CRGB::Red,
  360.     CRGB::Gray, // 'white' is too bright compared to red and blue
  361.     CRGB::Blue,
  362.     CRGB::Black,
  363.    
  364.     CRGB::Red,
  365.     CRGB::Gray,
  366.     CRGB::Blue,
  367.     CRGB::Black,
  368.    
  369.     CRGB::Red,
  370.     CRGB::Red,
  371.     CRGB::Gray,
  372.     CRGB::Gray,
  373.     CRGB::Blue,
  374.     CRGB::Blue,
  375.     CRGB::Black,
  376.     CRGB::Black
  377. };
  378.  
  379. void FillLEDsFromPaletteColors(uint8_t colorIndex)
  380. {
  381.     uint8_t brightness = 255;
  382.    
  383.     for( int i = 0; i < NUM_LEDS_REAL; i++) {
  384.         leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
  385.         colorIndex += 3;
  386.     }
  387.     FastLED.show();
  388. }
  389.  
  390. void PalletLoop()
  391. {
  392.     //ChangePalettePeriodically();
  393.    
  394.     static uint8_t startIndex = 0;
  395.     startIndex = startIndex + 10; /* motion speed */
  396.    
  397.     FillLEDsFromPaletteColors( startIndex);
  398.    
  399.     FastLED.show();
  400.     FastLED.delay(2000 / UPDATES_PER_SECOND);
  401. }
  402.  
  403. void SolidColors()
  404. {
  405.   int MyDelay = 40;
  406.   int MyColor = random16(15,64);
  407.   int MyHue = random16(175,255);
  408.   fill_solid(tempEven, STRIP_EVEN,CHSV(MyColor,MyHue,255)); //SET TEMP EVEN STRIP
  409.   fill_solid(tempOdd, STRIP_ODD, CHSV(MyColor,MyHue,255)); //SET TEMP ODD STRIP
  410.   part4 = tempEven;
  411.   FastLED.show();
  412.   delay(MyDelay);
  413.   part5 = tempOdd;
  414.   FastLED.show();
  415.   delay(MyDelay);
  416.   part6 = tempEven;
  417.   FastLED.show();
  418.   delay(MyDelay);
  419.   part7 = tempOdd;
  420.   FastLED.show();
  421.   delay(MyDelay);
  422.   part8 = tempEven;
  423.   FastLED.show();
  424.   delay(MyDelay);
  425.   part9 = tempOdd;
  426.   FastLED.show();
  427.   delay(MyDelay);
  428.   part10 = tempEven;
  429.   FastLED.show();
  430.   delay(MyDelay);
  431.   part11 = tempOdd;
  432.   FastLED.show();
  433.   delay(MyDelay);
  434.   part12 = tempEven;
  435.   FastLED.show();
  436.   delay(MyDelay);
  437.   part13 = tempOdd;
  438.   FastLED.show();
  439.   delay(MyDelay);
  440.   part14 = tempEven;
  441.   FastLED.show();
  442.   delay(MyDelay);
  443.   part15 = tempOdd;
  444.   FastLED.show();
  445.   delay(MyDelay);
  446.   part16 = tempEven;
  447.   FastLED.show();
  448.   delay(MyDelay);
  449.   part1 = tempOdd;
  450.   FastLED.show();
  451.   delay(MyDelay);
  452.   part2 = tempEven;
  453.   FastLED.show();
  454.   delay(MyDelay);
  455.   part3 = tempOdd;
  456.   FastLED.show();
  457.   delay(MyDelay);
  458.    
  459. }
  460.  
  461. void Marquee() {
  462.  
  463.   EVERY_N_MILLISECONDS(holdTime){  // Advance pixels to next position.
  464.    
  465.     if (DEBUG==1) {  // Print out some info if DEBUG is true.
  466.       Serial.print("delta: "); Serial.print(delta);
  467.       Serial.print("   spacing: "); Serial.print(spacing); Serial.print("    ");}
  468.      
  469.     for (uint8_t i=0; i<(NUM_LEDS_REAL/spacing); i++){
  470.       for (uint8_t w = 0; w<width; w++){
  471.         pos = (spacing * (i-1) + spacing + advance + w) % NUM_LEDS_REAL;
  472.         if ( w % 2== 0 ){  // Is w even or odd?
  473.           color = hue;
  474.         } else {
  475.           color = hue + hue2_shift;
  476.         }
  477.        
  478.         leds[pos] = CHSV(color,255,255);
  479.       }
  480.      
  481.       if (DEBUG==1) {  // Print out lit pixels if DEBUG is true.
  482.         Serial.print(" "); Serial.print(pos);
  483.       }
  484.     }
  485.     if (DEBUG==1) { Serial.println(" "); }
  486.     FastLED.show();
  487.      
  488.     // Fade out tail or set back to black for next loop around.
  489.     if (fadingTail == 1) {
  490.       fadeToBlackBy(leds, NUM_LEDS_REAL,fadeRate);
  491.     } else {
  492.       for (uint8_t i=0; i<(NUM_LEDS/spacing); i++){
  493.         for (uint8_t w = 0; w<width; w++){
  494.           pos = (spacing * (i-1) + spacing + advance + w) % NUM_LEDS;
  495.           leds[pos] = CRGB::Black;
  496.         }
  497.       }
  498.     }
  499.  
  500.     // Advance pixel postion down strip, and rollover if needed.
  501.     advance = (advance + delta + NUM_LEDS_REAL) % NUM_LEDS_REAL;
  502.   }
  503. }
  504.  
  505.  
  506. const TProgmemPalette16 Anjunabeach_p PROGMEM =
  507. {
  508.     CRGB::Red,
  509.     CRGB::Orange, // 'white' is too bright compared to red and blue
  510.     CRGB::Yellow,
  511.     CRGB::Black,
  512.    
  513.     CRGB::Red,
  514.     CRGB::Orange,
  515.     CRGB::Yellow,
  516.     CRGB::Black
  517.    
  518. //    CRGB::Red,
  519. //    CRGB::Red,
  520. //    CRGB::Orange,
  521. //    CRGB::Orange,
  522. //    CRGB::Yellow,
  523. //    CRGB::Yellow,
  524. //    CRGB::Blue,
  525. //    CRGB::Blue
  526. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement