Advertisement
Guest User

Untitled

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