Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.97 KB | None | 0 0
  1. // FastLED Setup
  2. #include "FastLED.h"
  3. #define LEDstrips 14
  4. #define LEDper 60
  5. #define LEDtype WS2813
  6. #define LEDcorr TypicalSMD5050
  7. #define LEDdither 255     //try 0 to reduce flickering
  8. uint8_t LEDbright = 15;
  9. CRGB leds[LEDstrips][LEDper];
  10. uint8_t seed;
  11. uint8_t hue;
  12.  
  13. // MSGEQ7
  14. #include "MSGEQ7.h"
  15. #define EQ7pin A0
  16. #define EQ7reset PIN_B0
  17. #define EQ7strobe PIN_B1
  18. #define EQ7interval ReadsPerSecond(50)
  19. #define EQ7smooth true
  20. #define nz 30
  21. CMSGEQ7<EQ7smooth, EQ7reset, EQ7strobe, EQ7pin> MSGEQ7;
  22. uint8_t EQ7max[7];
  23. uint8_t EQ7counter[7];
  24.  
  25. // Remote                    check IRLremote.h
  26. #include <IRremote.h>
  27. IRrecv irrecv(PIN_C0);
  28. decode_results results;
  29. int IRhold;
  30.  
  31. void setup() {
  32.    // Initialize LEDs
  33.    FastLED.setMaxPowerInVoltsAndMilliamps(5,450); //play wit hthe order here
  34.    FastLED.setBrightness(LEDbright);
  35.    FastLED.setDither(LEDdither);
  36.    FastLED.clear();
  37.    FastLED.addLeds<LEDtype, PIN_C7>(leds[0], LEDper).setCorrection(LEDcorr);
  38.    FastLED.addLeds<LEDtype, PIN_C6>(leds[1], LEDper).setCorrection(LEDcorr);
  39.    FastLED.addLeds<LEDtype, PIN_C5>(leds[2], LEDper).setCorrection(LEDcorr);
  40.    FastLED.addLeds<LEDtype, PIN_C4>(leds[3], LEDper).setCorrection(LEDcorr);
  41.    FastLED.addLeds<LEDtype, PIN_C3>(leds[4], LEDper).setCorrection(LEDcorr);
  42.    FastLED.addLeds<LEDtype, PIN_C2>(leds[5], LEDper).setCorrection(LEDcorr);
  43.    FastLED.addLeds<LEDtype, PIN_C1>(leds[6], LEDper).setCorrection(LEDcorr);
  44.    FastLED.addLeds<LEDtype, PIN_F1>(leds[7], LEDper).setCorrection(LEDcorr);
  45.    FastLED.addLeds<LEDtype, PIN_F2>(leds[8], LEDper).setCorrection(LEDcorr);
  46.    FastLED.addLeds<LEDtype, PIN_F3>(leds[9], LEDper).setCorrection(LEDcorr);
  47.    FastLED.addLeds<LEDtype, PIN_F4>(leds[10], LEDper).setCorrection(LEDcorr);
  48.    FastLED.addLeds<LEDtype, PIN_F5>(leds[11], LEDper).setCorrection(LEDcorr);
  49.    FastLED.addLeds<LEDtype, PIN_F6>(leds[12], LEDper).setCorrection(LEDcorr);
  50.    FastLED.addLeds<LEDtype, PIN_F7>(leds[13], LEDper).setCorrection(LEDcorr);
  51.    FastLED.clear();
  52.    FastLED.show(); // do I need a show after a clear?
  53.  
  54.    // Initialize other components & diagnostic
  55.    irrecv.enableIRIn();
  56.    Serial.begin(9600);
  57.    MSGEQ7.begin();
  58. }
  59.  
  60. void loop() { //could just move boot pattern here if it has an IR break in it
  61.   remote();
  62. }
  63.  
  64. void remote(){
  65.   void waterfall();
  66.   void rando();
  67.   void snow();
  68.   void frogger();
  69.  
  70.   if (irrecv.decode(&results)) {            //input might be cut off after receving first value, will need to store immediately if so
  71.           Serial.print ("first val  ");
  72.       Serial.print (results.value, HEX);
  73.     if(results.value == 0XFFFFFFFF){
  74.  
  75.       results.value = IRhold;
  76.     } else {
  77.       IRhold = results.value;
  78.     }
  79.     Serial.print ("adjusted val");
  80.     Serial.println(results.value, HEX); // display the value
  81.     switch(results.value){
  82.       case 0xFF30CF:    // "1"
  83.         vizualiser();   //goto
  84.         break;
  85.       case 0xFF18E7:    // "2"
  86.         waterfall();
  87.         break;
  88.       case 0xFF7A85:    // "3"
  89.         rando();
  90.         break;
  91.       case 0xFF10EF:    // "4"
  92.         snow();
  93.         break;
  94.       case 0xFF38C7:    // "5"
  95.         frogger();
  96.         break;
  97.       case 0xFFA25D:    // "Power"    
  98.         FastLED.clear();
  99.         FastLED.show();
  100.         remote();
  101.         break;
  102.       case 0xFFE01F:    // "Down"
  103.         LEDbright = LEDbright - 5;
  104.         FastLED.setBrightness(LEDbright);
  105.         FastLED.show();
  106.         break;
  107.       case 0xFF906F:    // "Up"
  108.         LEDbright = LEDbright + 5;
  109.         FastLED.setBrightness(LEDbright);
  110.         FastLED.show();
  111.         break;
  112.     }
  113.   irrecv.resume(); // receive the next value
  114.   }
  115. }
  116.  
  117. void vizualiser(){
  118.   while(1){
  119.     bool newReading = MSGEQ7.read(EQ7interval); // Look for new reading
  120.    
  121.     if (newReading) {
  122.       FastLED.clear();
  123.       for(int s = 0; s < LEDstrips/2; s++){     // For each fq
  124.         uint8_t fq = MSGEQ7.get(s);             // Get reading  
  125.         fq = mapNoise(fq, nz, 255, 0, 255);     // Reduce noise
  126.         fq = map(fq, 0, 255, 0, LEDper);        // Scale values to length of strips
  127.   /*
  128.         if(fq > EQ7max[s]) {                    // Rescale maximums
  129.           EQ7max[s] = fq;
  130.           } else {
  131.           EQ7reset[s]++;
  132.           if(EQ7reset[s] = 255){
  133.             EQ7max[s] = fq;
  134.   //        EQ7reset++;        
  135.          }
  136.      */    
  137.         for(int l = 0; l < fq; l++){            // Write values
  138.           leds[s][l].setHSV(hue+l*5, 255, 255);
  139.           leds[13-s][l].setHSV(hue+l*5, 255, 255);
  140.          
  141.  
  142.           }
  143.        }
  144.     }
  145.     FastLED.show();
  146.     hue++;
  147.     delay(30);
  148.     //if (irrecv.decode(&results)) {
  149.     //  break;
  150.      // irrecv.resume();
  151.    // }
  152.   }
  153. }
  154.  
  155.  
  156. void snow(){
  157.   for (int i=0; i<1000; i++){  // runs 3 times - better boot pattern? (fade?)
  158.     for (int x=0; x<LEDstrips; x++){  //rows
  159.       for (int y=0; y<LEDper; y++){ //columns
  160.         leds[x][y] = CHSV( random8(), random8(), 255);
  161.       }
  162.     }
  163.     FastLED.show();
  164.     delay(50);        // adjust so change is visible  
  165.   }  
  166. }
  167.  
  168. void rando(){
  169.   for (int i=0; i<1000; i++){  // runs 3 times - better boot pattern? (fade?)
  170.     leds[random8(0, LEDstrips)][random8(0, LEDper)] = CHSV( random8(), random8(), random8(155,255));
  171.     delay(1);        // adjust so change is visible
  172.     FastLED.show();
  173.   }  
  174. }
  175.  
  176. void scan(){
  177.    for (int leng=0; leng < LEDper; leng++){ //can make this a while loop, and make length proportional to delay
  178.       for (int wide=0; wide < LEDstrips; wide++){
  179.          leds[wide][leng] = CHSV(seed, random8(100,255), 255);
  180.       }
  181.      // FastLED.show();
  182.      // delayMicroseconds(1);
  183.  
  184.    }
  185.    seed++;
  186.    FastLED.show();
  187.    delay(300);
  188. }
  189.  
  190. void waterfall(){
  191.   int rowcount = 0;
  192.   while (1){
  193.     for (int row = 0; row < rowcount/10; row++){
  194.       for (int col = 0; col < LEDstrips; col++){         // Write each row with start colour and a random saturation      
  195.         leds[col][row] = CHSV(hue + row*5, 255, 255); //random(155,255)
  196.         }    
  197.             hue = hue + 1;
  198.  
  199.     }
  200.     FastLED.show();
  201.     delay(50);
  202.  
  203.     if(rowcount/10 < LEDper){rowcount = rowcount+1;}
  204.   }
  205. }
  206.  
  207. // Diagonal - this wont work, but it will be dope!
  208. void diagonal(){
  209.     int rowpass = 0;
  210.     int colpass = 0;
  211.     int diagseed = random8();
  212.     while (colpass < LEDstrips && rowpass < LEDper){
  213.        for (int c = 0; c < colpass; c++){
  214.           for (int r = 0; r < rowpass; r++){
  215.              leds[r][c] = CHSV (diagseed++, 255, 255);
  216.              FastLED.show();
  217.              delay(1);
  218.           }
  219.           rowpass++;
  220.        }
  221.        colpass++;
  222.     }
  223. }
  224.  
  225. void spiral(int m, int n){
  226.    int i, currRow = 0, currCol = 0;
  227.    while (currRow < LEDstrips && currCol <LEDper) { //might have to define COL
  228.       for (i = currCol; i < n; i++) {          //print the first row normally
  229.          leds[currRow][i] = CHSV (seed, 255, LEDbright);
  230.          seed++;          // make sure this is kosher
  231.          FastLED.show();
  232.          // cout << spiral[currRow][i]<<" ";  //replace with LED
  233.       }
  234.       currRow++;           //point to next row
  235.  
  236.       for (i = currRow; i < m; ++i) {       //Print the last column
  237.          leds[i][n-1] = CHSV (seed, 255, LEDbright);
  238.          seed++;
  239.          FastLED.show();        
  240.          // cout << spiral[i][n-1]<<" ";
  241.       }
  242.  
  243.       n--;               //set the n-1th column is current last column
  244.  
  245.       if ( currRow< m) {         //when currRow is in the range, print the last row
  246.          for (i = n-1; i >= currCol; --i) {
  247.             leds[m-1][i] = CHSV (seed, 255, LEDbright);
  248.             seed++;
  249.             FastLED.show();
  250.             // cout << spiral[m-1][i]<<" ";
  251.          }
  252.          m--; //decrease the row range
  253.       }
  254.  
  255.       if (currCol <n) {      //when currCol is in the range, print the fist column
  256.          for (i = m-1; i >= currRow; --i) {
  257.             leds[i][currCol] = CHSV (seed, 255, LEDbright);
  258.             seed++;
  259.             FastLED.show();
  260.             // cout << spiral[i][currCol]<<" ";
  261.          }
  262.          currCol++;
  263.       }
  264.    }
  265. }
  266.  
  267. void frogger(){
  268.   for(int i = 0; i < 1000; i++){
  269.     for(int col = 0; col < LEDstrips; col++){
  270.       for(int row = 0; row <LEDper; row++){
  271.         leds[col][row] = CHSV(seed*5*(1+(-2*col%2)), 255, 255); // negative is to alternate rows
  272.       }
  273.     }
  274.     seed++;
  275.   }
  276.   for(int i = 0; i < 1000; i++){
  277.     for(int row = 0; row < LEDper; row++){
  278.       for(int col = 0; col < LEDstrips; col++){
  279.         leds[col][row] = CHSV(seed*5*(1+(-2*col%2)), 255, 255);
  280.       }
  281.     }
  282.   }
  283. }
  284. /*
  285. void dispSpiral(int m, int n){
  286.    int i, currRow = 0, currCol = 0;
  287.    int spiralseed = random8();
  288.    while (currRow < ROW && currCol <COL) { //might have to define COL
  289.       for (i = currCol; i < n; i++) {          //print the first row normally
  290.          leds[curr row][i] = CHSV (spiralseed, 255, bright);
  291.          spiralseed++;          // make sure this is kosher
  292.          FastLED.show();
  293.          // cout << spiral[currRow][i]<<" ";  //replace with LED
  294.       }
  295.       currRow++;           //point to next row
  296.  
  297.       for (i = currRow; i < m; ++i) {       //Print the last column
  298.          leds[i][n-1] = CHSV (spiralseed, 255, bright);
  299.          spiralseed++;
  300.          FastLED.show();        
  301.          // cout << spiral[i][n-1]<<" ";
  302.       }
  303.  
  304.       n--;               //set the n-1th column is current last column
  305.  
  306.       if ( currRow< m) {         //when currRow is in the range, print the last row
  307.          for (i = n-1; i >= currCol; --i) {
  308.             leds[m-1][i] = CHSV (spiralseed, 255, bright);
  309.             spiralseed++;
  310.             FastLED.show();
  311.             // cout << spiral[m-1][i]<<" ";
  312.          }
  313.          m--; //decrease the row range
  314.       }
  315.  
  316.       if (currCol <n) {      //when currCol is in the range, print the fist column
  317.          for (i = m-1; i >= currRow; --i) {
  318.             leds[i][currcol] = CHSV (spiralseed, 255, bright);
  319.             spiralseed++;
  320.             FastLED.show();
  321.             // cout << spiral[i][currCol]<<" ";
  322.          }
  323.          currCol++;
  324.       }
  325.    }
  326. }
  327.  
  328. // Tasks
  329.         Add fade to black shutdown/sleep
  330.         Easing and Linear Interpolation functions
  331.         leds[14][60] += leds[14][60]
  332.         Put breaks
  333.         Spiral in/out -> reverse?
  334.         figure out fill rainbow
  335.         Remove delay
  336.        
  337. // one of these two will be more efficient
  338. fill_rainbow( &(leds[LEDstrips][LEDper]), LEDstrips * LEDper, 0); //Basic
  339.     or
  340. seed = random8();
  341. For (int x=0; x<LEDstrips; x++){
  342.    fill_rainbow( &(leds[x][]), LEDper, seed; //random is start value
  343.    FastLED.show();
  344.    delayMiliseconds(100);
  345. }
  346.    // diagonal
  347.    // do all on first row, adding 1, then do next row adding one
  348.    for(int i=0; i{}
  349.    leds[][] = CHSV
  350. // Timers
  351. void dispWarp() {
  352.   unsigned long currentMillis1 = millis() % 20000;
  353.   if(currentMillis1 < 10000) {
  354.     int x = map(currentMillis1, 0, 9999, 0, 128);
  355.     //turn on x number of LEDs
  356.   }
  357.   else {
  358.     int x = map(currentMillis1, 10000, 19999, 128, 0);
  359.     //turn on x number of LEDs
  360.   }
  361. }
  362. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement