SHARE
TWEET

Untitled

a guest Jan 14th, 2020 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // FastLED Setup
  2. #define FASTLED_INTERNAL
  3. #include "FastLED.h"
  4. #define LEDstrips 28
  5. #define LEDper 60
  6. #define LEDtype WS2813
  7. #define LEDcorr TypicalSMD5050
  8. #define LEDdither 255     //try 0 to reduce flickering
  9. uint8_t LEDbright = 100;
  10. int LEDamps = 1000;
  11. CRGB leds[LEDstrips][LEDper];
  12. uint8_t hue = 155;
  13. int rowcount;
  14. int colcount;
  15. int count;
  16. byte glitterchance = 0;
  17.  
  18. // MSGEQ7
  19. #include "MSGEQ7.h"
  20. #define EQ7pin A7
  21. #define EQ7reset PIN_C7
  22. #define EQ7strobe PIN_C5
  23. #define EQ7interval ReadsPerSecond(50)
  24. #define EQ7smooth 200
  25. #define nz 20
  26. CMSGEQ7<EQ7smooth, EQ7reset, EQ7strobe, EQ7pin> MSGEQ7;
  27. float EQ7avg[7];
  28. float EQ7peak[7];
  29.  
  30. DEFINE_GRADIENT_PALETTE( purplecascade ){
  31.    0,     0,  0,  0,   //black
  32.   120,   155,  0,  255,   //purple
  33.   235,   255, 0,  40,   //crimson
  34.   255,   255,255,255 }; //full white
  35.  
  36. DEFINE_GRADIENT_PALETTE( cyber ){
  37.     0,    0, 0, 0,
  38.     120,    240,0,0,
  39.     235,    255,  200,  0,
  40.     255,    255,255,255
  41. };
  42.  
  43. DEFINE_GRADIENT_PALETTE( blackwhite ){
  44.     0,    0, 0, 0,
  45.   127,    0, 0, 0,
  46.   128,  255, 255, 255,
  47.   255,  255, 255, 255};
  48.  
  49. void setup() {
  50.   // put your setup code here, to run once:
  51.   // Initialize LEDs
  52.    FastLED.setMaxPowerInVoltsAndMilliamps(5,LEDamps); //play with the order here
  53.    //FastLED.setTemperature();
  54.    FastLED.setBrightness(LEDbright);
  55.    FastLED.setDither(LEDdither);
  56.    FastLED.addLeds<LEDtype, PIN_C4, GRB>(leds[0], LEDper).setCorrection(LEDcorr);
  57.    FastLED.addLeds<LEDtype, PIN_C3, GRB>(leds[1], LEDper).setCorrection(LEDcorr);
  58.    FastLED.addLeds<LEDtype, PIN_C2, GRB>(leds[2], LEDper).setCorrection(LEDcorr);
  59.    FastLED.addLeds<LEDtype, PIN_C1, GRB>(leds[3], LEDper).setCorrection(LEDcorr);
  60.    FastLED.addLeds<LEDtype, PIN_C0, GRB>(leds[4], LEDper).setCorrection(LEDcorr);
  61.    FastLED.addLeds<LEDtype, PIN_E1, GRB>(leds[5], LEDper).setCorrection(LEDcorr);
  62.    FastLED.addLeds<LEDtype, PIN_E0, GRB>(leds[6], LEDper).setCorrection(LEDcorr);
  63.    FastLED.addLeds<LEDtype, PIN_D7, GRB>(leds[7], LEDper).setCorrection(LEDcorr);
  64.    FastLED.addLeds<LEDtype, PIN_D6, GRB>(leds[8], LEDper).setCorrection(LEDcorr);
  65.    FastLED.addLeds<LEDtype, PIN_D5, GRB>(leds[9], LEDper).setCorrection(LEDcorr);
  66.    FastLED.addLeds<LEDtype, PIN_D4, GRB>(leds[10], LEDper).setCorrection(LEDcorr);
  67.    FastLED.addLeds<LEDtype, PIN_D1, GRB>(leds[11], LEDper).setCorrection(LEDcorr);
  68.    FastLED.addLeds<LEDtype, PIN_D0, GRB>(leds[12], LEDper).setCorrection(LEDcorr);
  69.    FastLED.addLeds<LEDtype, PIN_B7, GRB>(leds[13], LEDper).setCorrection(LEDcorr);
  70.    FastLED.addLeds<LEDtype, PIN_B4, GRB>(leds[14], LEDper).setCorrection(LEDcorr);
  71.    FastLED.addLeds<LEDtype, PIN_B3, GRB>(leds[15], LEDper).setCorrection(LEDcorr);
  72.    FastLED.addLeds<LEDtype, PIN_B2, GRB>(leds[16], LEDper).setCorrection(LEDcorr);
  73.    FastLED.addLeds<LEDtype, PIN_B1, GRB>(leds[17], LEDper).setCorrection(LEDcorr);
  74.    FastLED.addLeds<LEDtype, PIN_B0, GRB>(leds[18], LEDper).setCorrection(LEDcorr);
  75.    FastLED.addLeds<LEDtype, PIN_E7, GRB>(leds[19], LEDper).setCorrection(LEDcorr);
  76.    FastLED.addLeds<LEDtype, PIN_E6, GRB>(leds[20], LEDper).setCorrection(LEDcorr);
  77.    FastLED.addLeds<LEDtype, PIN_F0, GRB>(leds[21], LEDper).setCorrection(LEDcorr);
  78.    FastLED.addLeds<LEDtype, PIN_F1, GRB>(leds[22], LEDper).setCorrection(LEDcorr);
  79.    FastLED.addLeds<LEDtype, PIN_F2, GRB>(leds[23], LEDper).setCorrection(LEDcorr);
  80.    FastLED.addLeds<LEDtype, PIN_F3, GRB>(leds[24], LEDper).setCorrection(LEDcorr);
  81.    FastLED.addLeds<LEDtype, PIN_F4, GRB>(leds[25], LEDper).setCorrection(LEDcorr);
  82.    FastLED.addLeds<LEDtype, PIN_F5, GRB>(leds[26], LEDper).setCorrection(LEDcorr);
  83.    FastLED.addLeds<LEDtype, PIN_F6, GRB>(leds[27], LEDper).setCorrection(LEDcorr);
  84.    FastLED.clear();
  85.    FastLED.show();
  86.  
  87.    // Initialize other components
  88.    Serial.begin(9600);
  89.    
  90.   Serial.println("start");
  91. }
  92.  
  93. void loop() {        //add state 1 mili?
  94.   dualwave();
  95.   //doublehelix();
  96.  
  97.   hue = hue + 1;
  98.   FastLED.show();
  99. }
  100. /*oid spiral(){
  101.   FastLED.clear();
  102.   byte hueadd = 0;
  103.   byte top = 0;
  104.   byte right = LEDstrips -1;
  105.   byte bottom = LEDper - 1;
  106.   byte left = 0;
  107.  
  108.  
  109.   while(top < (LEDper/2 - 1) && right > (LEDstrips/2 - 1) && bottom > (LEDstrips/2 - 1) && left < (LEDstrips/2 - 1)){
  110.     for(int col = left; col < right; col++){
  111.       leds[col][top] = CHSV(hue+hueadd, 255, 255);
  112.       hueadd++;
  113.       FastLED.show();
  114.     }
  115.     top++;
  116.    
  117.     for(int row = top; row < bottom; row++){
  118.       leds[right][row] = CHSV(hue+hueadd, 255, 255);
  119.       hueadd++;
  120.       FastLED.show();
  121.     }
  122.     right--;
  123.  
  124.     for(int col = right; col > left; col++){
  125.       leds[col][bottom] = CHSV(hue+hueadd, 255, 255);
  126.       hueadd++;
  127.       FastLED.show();
  128.     }
  129.     bottom--;
  130.  
  131.     for(int row = bottom; row > top; row++){
  132.       leds[left][row] = CHSV(hue+hueadd, 255, 255);
  133.       hueadd++;
  134.       FastLED.show();
  135.     }
  136.     left++;
  137.   }
  138. }
  139. */
  140.  
  141. void dualwave(){
  142.   FastLED.clear();
  143.   CRGBPalette16 palette = cyber;
  144.  
  145.  
  146.   for(int x = 0; x < LEDper; x++){
  147.     uint8_t stungus = (hue + count + x*beatsin8(1, 1, 8));      // Fill sine status
  148.     stungus = sin8(stungus);
  149.     uint8_t gungus = stungus + 128;
  150.     stungus = map(stungus, 0, 255, 2, 25);
  151.     gungus = map(gungus, 0, 255, 2, 25);
  152.    
  153.  
  154.     leds[stungus][x] = CHSV(255, 0, 0);
  155.     leds[gungus][x] = CHSV(255, 0, 0);
  156.     for(byte left = 0; left < stungus; left++){
  157.      
  158.       leds[left][x] = ColorFromPalette(palette, rowcount + x*5, 255, LINEARBLEND);
  159.     }
  160.     CRGBPalette16 palette = purplecascade;
  161.     for(byte right = LEDstrips-1; right > gungus; right--){
  162.      leds[right][x] = ColorFromPalette(palette, hue + x*5, 255, LINEARBLEND);
  163.     }
  164.   }
  165.   count++;
  166.   rowcount = rowcount - beatsin8(20, 1, 7);
  167.   hue = hue + beatsin8(10, 1, 6);
  168. }
  169.  
  170. void doublehelix(){
  171.   FastLED.clear();
  172.  
  173.   for(int x = 0; x < LEDper; x++){
  174.     uint8_t stungus = (hue + count + x*2);  // beatsin8(1, 1, 8)
  175.     stungus = sin8(stungus);                        // Calculate sine position
  176.     uint8_t gungus = stungus + 128;                 // Copy 180 degrees out of phase
  177.     stungus = map(stungus, 0, 255, 2, 25);          // Map to LEDs
  178.     gungus = map(gungus, 0, 255, 2, 25);  
  179.  
  180.     for(byte col = 0; col < LEDper; col++){
  181.       if(col < stungus && col < gungus){  
  182.         CRGBPalette16 palleft = cyber;
  183.         leds[col][x] = ColorFromPalette(palleft, rowcount + x*5, 255, LINEARBLEND);
  184.         Serial.println("gug");
  185.       }
  186.       if(col > stungus && col > gungus){
  187.         CRGBPalette16 palright = purplecascade;
  188.         leds[col][x] = ColorFromPalette(palright, hue + x*5, 255, LINEARBLEND);
  189.       }
  190.       if(col > stungus && col < gungus){
  191.         CRGBPalette16 palmid = blackwhite;
  192.         leds[col][x] = ColorFromPalette(palmid, rowcount + x*5, 255, LINEARBLEND);                 // * beatsin(5, -1000, 1000)/1000
  193.       }
  194.       if(col < stungus && col > gungus){
  195.         CRGBPalette16 palmid = blackwhite;
  196.         leds[col][x] = ColorFromPalette(palmid, rowcount + x*5, 255, LINEARBLEND);          
  197.       }
  198.      
  199.     }
  200.     leds[stungus][x] = CHSV(255, 0, 0);       // Write wave position
  201.     leds[gungus][x] = CHSV(255, 0, 0);
  202.   }
  203.   count++;
  204.   rowcount = rowcount - beatsin8(20, 1, 7);
  205.   hue = hue + beatsin8(10, 1, 6);
  206. }
  207.  
  208. void visualizer(){  
  209.   bool newReading = MSGEQ7.read(EQ7interval);         // Look for new reading (can remove if delay)
  210.  
  211.   if (newReading) {
  212.     FastLED.clear();
  213.     for(int s = 0; s < 7; s++){     // For each fq
  214.       uint8_t fq = MSGEQ7.get(s);         // Get reading
  215.       fq = mapNoise(fq, nz, 255, 0, 255);   // Reduce noise
  216.       EQ7avg[s] = EQ7avg[s] * 0.95 + fq * 0.05;          // Moving Average
  217.       fq = map(fq, 0, round(EQ7avg[s]), 0, LEDper);      // Scale values to length of strips
  218.  
  219.      
  220.       // Write values to LEDs
  221.       for(int leng = 0; leng < fq; leng++){                // Display as 00 11 22 33 44 55 66 66 55 44 33 22 11 00
  222.         leds[s*2][leng] = CHSV(hue+leng*5, 255, 255);
  223.         leds[1 + s*2][leng] = CHSV(hue+leng*5, 255, 255);
  224.         leds[LEDstrips-1-s*2][leng] = CHSV(hue+leng*5, 255, 255);
  225.         leds[LEDstrips-2-s*2][leng] = CHSV(hue+leng*5, 255, 255);
  226.       }
  227.      
  228.       // Peak detection
  229.       if( fq == 0 ){
  230.       } else if (round(EQ7peak[s]) > fq){
  231.         EQ7peak[s] = EQ7peak[s] * 0.9;            // can multiply to make exponential
  232.         leds[s*2][round(EQ7peak[s])] = CHSV(hue, 0, 255);
  233.         leds[1 + s*2][round(EQ7peak[s])] = CHSV(hue, 0, 255);
  234.         leds[LEDstrips-1-s*2][round(EQ7peak[s])] = CHSV(hue, 0, 255);
  235.         leds[LEDstrips-2-s*2][round(EQ7peak[s])] = CHSV(hue, 0, 255);
  236.       } else {
  237.         EQ7peak[s] = fq;
  238.         leds[s*2][fq] = CHSV(hue, 0, 255);
  239.         leds[1 + s*2][fq] = CHSV(hue, 0, 255);
  240.         leds[LEDstrips-1-s*2][fq] = CHSV(hue, 0, 255);
  241.         leds[LEDstrips-2-s*2][fq] = CHSV(hue, 0, 255);
  242.       }        
  243.     }
  244.  
  245.     // Beat Action
  246.     if(MSGEQ7.get(1) > 20*EQ7avg[1]){ // could put this in s loop and flash the individual strips     or   make it be the first 3 bands
  247.       for(int x = 0; x < LEDstrips; x++){
  248.         fill_solid (leds[x], LEDper, CRGB(255, 255, 255));
  249.       }  
  250.     }
  251.   }
  252. }
  253.  
  254. void snow(){
  255.   for(byte i = 0; i < LEDstrips; i++){            // Fade everything
  256.     leds[i].fadeToBlackBy( 64 );  
  257.   }  
  258.   for (int x = 0; x < colcount; x++){                                       // columns
  259.     for (int y = 0; y < rowcount; y++){                                     // rows
  260.       for(int i = 0; i < (rowcount+colcount)/3; i++){                       // paint lights proportional to how much of the display is being updated
  261.         leds[x][random8(LEDper)] = CHSV( random8(), random8(), 255);        // consider having these paint from inside out, instead of outside in
  262.         leds[LEDstrips-1-x][random8(LEDper)] = CHSV( random8(), random8(), 255);      // doubled for symmetry
  263.       }
  264.     }
  265.   }
  266.   // Roll counters forward and wrap at boundaries
  267.   rowcount++;
  268.   colcount++;
  269.   if(colcount == LEDstrips/2){
  270.     colcount = 0;
  271.   }
  272.   if(rowcount == LEDper){
  273.     rowcount = 0;
  274.   }
  275. }
  276.  
  277. void initialization(){
  278.   CRGBPalette16 PALstart = startup;
  279.  
  280.   for(int y = 0; y < LEDper; y++){            //read original values from array and add hue mod
  281.     for(int x = 0; x < LEDstrips; x++){
  282.       uint8_t data = pgm_read_byte_near(&startarray[y*LEDstrips+x];         // Get map value
  283.       if(data == 2){            //red                                       // Colour according to map value
  284.         leds[x][y] = ColorFromPalette( PALstart, 0+hue+abs(13-x), NOBLEND);
  285.       } else if(data == 3){      //yellow
  286.         leds[x][y] = ColorFromPalette( PALstart, 51+hue+abs(13-x), NOBLEND);
  287.       } else if(data == 4){     //green
  288.         leds[x][y] = ColorFromPalette( PALstart, 102+hue+abs(13-x), NOBLEND);
  289.       } else if(data == 5){     //cyan
  290.         leds[x][y] = ColorFromPalette( PALstart, 153+hue+abs(13-x), NOBLEND);
  291.       } else if(data == 6){     //blue
  292.         leds[x][y] = ColorFromPalette( PALstart, 204+hue+abs(13-x), NOBLEND);
  293.       } else if(data == 1){     //white
  294.         leds[x][y] = CHSV(255, 0, 255);
  295.       } else {                                //black
  296.         leds[x][y] = CHSV(0, 0, 0);
  297.       }
  298.     }
  299.   }
  300.   hue++;
  301. }
  302.  
  303. void seanbox(){ //rowcount and colcount must be 1 instead of 0 to avoid divide-by-zero
  304.   for (int col = 0; col < colcount; col++){
  305.     for(int row = 0; row < rowcount; row++){
  306.       int x = col;
  307.       int y = row % (2*colcount); //distance from top of pattern
  308.       int y2 = (2*colcount)-1 - y; //distance from bottom of pattern
  309.       if (y < y2) { //pattern moves right
  310.         if(x > y ){
  311.           leds[col][row] = CHSV(hue+(row + x - y)*15, 255, 255);
  312.         }
  313.         else {
  314.           leds[col][row] = CHSV(hue+row*15, 255, 255);
  315.         }
  316.       }
  317.       else //pattern moves left
  318.       {
  319.         if(x > y2){
  320.           leds[col][row] = CHSV(hue+(row + y2 - x)*15, 255, 255);
  321.         }
  322.         else {
  323.           leds[col][row] = CHSV(hue+row*15, 255, 255);
  324.         }
  325.       }
  326.  
  327.     }
  328.   }
  329.   hue  = hue + 11;
  330.   count = (count+1)%10; //cycle through 10 numbers
  331.   if (count == 0) { //every 10 iterations, do this
  332.     if(rowcount < LEDper){rowcount++;}
  333.     if(colcount < LEDstrips){colcount++;}
  334.   }
  335. }
  336.  
  337. RainbowColors_p;
  338. RainbowStripeColors_p;
  339. CloudColors_p;
  340. PartyColors_p;
  341. LavaColors_p;
  342. OceanColors_p;
  343. ForestColors_p;
  344. HeatColors_p;
  345.  
  346. /*
  347.  
  348. void paletteknife(){
  349.   uint8_t BLEpalette[20];    // goes up top              // Needs to be 4 times however many colors are being used.
  350.  
  351.   hsv = CHSV(random8(), 255, 255);  // pick random hue
  352.   hsv2rgb_rainbow( hsv, rgb);       // convert to R,G,B
  353.  
  354.   for(byte x = 0; X < BLEsecondary; x++){
  355.     strtokIndx = strtok(NULL, ",");
  356.     palettedata[x] = atoi(strtokIndx);
  357.   }
  358.   dynamicpal = palettedata;
  359. }
  360.  
  361. void BLEparse() {
  362.     char * strtokIndx;                          // this is used by strtok() as an index  
  363.     strtokIndx = strtok(BLEtempchars,",");      // get the first part - the string
  364.     strcpy(BLEprimary, strtokIndx);             // copy it to messageFromPC
  365.     strtokIndx = strtok(NULL, ",");             // this continues where the previous call left off
  366.     BLEsecondary = atoi(strtokIndx);            // convert this part to an integer
  367.     for(byte x = 0; X < BLEsecondary; x++){
  368.       strtokIndx = strtok(NULL, ",");
  369.       BLEpalette[x] = atoi(strtokIndx);
  370.     }
  371. }
  372.  
  373. else if (strcmp(BLEprimary, "Palette") == 0){
  374.   dynamicpal = BLEpalette;
  375. }
  376.  
  377.  
  378. void waterfall(){
  379.   for (int row = 0; row < rowcount/2; row++){
  380.     for (int col = 0; col < LEDstrips; col++){         // Write each row with start colour and a random saturation      
  381.       leds[col][row] = CHSV(hue + row*5, 255, 255); //random(155,255)
  382.     }          
  383.   }
  384.   hue = hue - 4;
  385.   FastLED.show();
  386.   if(rowcount/2 < LEDper){
  387.     rowcount++;
  388.   }
  389. }
  390.  
  391.  
  392. */
  393.  
  394. // Adjust start pal colour locations
  395. // make seanbox move faster
  396. // adjust power switch (just make it go to default amps
  397. // update random numbers -> random8(n) random from 0 to n-1
  398. //   random8()       == random from 0..255
  399. //   random8( n)     == random from 0..(N-1)
  400. //   random8( n, m)  == random from N..(M-1)
  401.  
  402. //switch snow function to fade to black by (20)
  403. //HSV color ramp: blue purple ping red orange yellow (and back) Basically, everything but the greens, which tend to make people's skin look unhealthy.
  404. // on initialization, change to no blend
  405.  
  406. /*
  407.  
  408.  */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top