Advertisement
Guest User

Untitled

a guest
Feb 16th, 2020
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.77 KB | None | 0 0
  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 = 10;
  10. int LEDamps = 3000;
  11. CRGB leds[LEDstrips][LEDper];
  12. CRGBPalette16 dynamicpal;
  13. uint8_t hue = 155;
  14. bool palshuffle = false;
  15.  
  16. //String BLEupfactors[] = {"bright", "amps", "speed", "bpm"};
  17. //String BLEupdata[] = {LEDbright, LEDamps, STATEloopinterval, bpm};
  18. byte rotator = 0;
  19. int8_t blendspeed = 24;
  20.  
  21. /////////////////////////////////////////////////////////////////////////////
  22. DECLARE_GRADIENT_PALETTE( borderrainbow ){
  23.    0,     0,  0,  0,
  24.   115,   255,  0,  0,
  25.   185,   0, 255,  0,
  26.   255,   0,0,255 };
  27.  
  28. DECLARE_GRADIENT_PALETTE( purplecascade ){ //GRB
  29.     0,     0,  0,  0,   //black
  30.   120,   155,  0,  255,   //purple
  31.   235,   255,  0,  40,   //crimson
  32.   255,   255, 255, 255 }; //full white
  33.  
  34. DECLARE_GRADIENT_PALETTE( blackwhite ){
  35.     0,    0, 0, 0,
  36.   127,    0, 0, 0,
  37.   128,  255, 255, 255,
  38.   255,  255, 255, 255};
  39.  
  40. DECLARE_GRADIENT_PALETTE( newspaper ){
  41.     0,    0, 0, 0,
  42.   127,    0, 0, 0,
  43.   128,  255, 255, 255,
  44.   255,  255, 0, 0};
  45.  
  46. DECLARE_GRADIENT_PALETTE( sunburst ){
  47.     0,    0, 0, 0,
  48.   120,  255, 255, 0,
  49.   235,  255, 255, 255,
  50.   255,  255, 255, 255};
  51.  
  52. DECLARE_GRADIENT_PALETTE( gilt ){
  53.     0,    0, 0, 0,
  54.   128, 96, 0, 140,
  55.   150, 255, 100, 0,
  56.   235,  255, 200, 0,
  57.   255,  255, 255, 255};
  58.  
  59. DECLARE_GRADIENT_PALETTE( tropicana ){
  60.     0,    0, 0, 0,
  61.   71, 66, 245, 230,
  62.   145, 255, 255, 255,
  63.   255,  245, 66, 203};
  64.  
  65. DEFINE_GRADIENT_PALETTE( startup ){ //RYGCB
  66.   0,   255,  0,  0,      //red
  67.   51,   255,  0,  0,
  68.   52,   255,  255,  0,    //yellow
  69.   102,  255,  255,  0,    
  70.   103,  0,  255,  0,      //green
  71.   153,  0,  255,  0,
  72.   154,  0,  255,  255,    //cyan
  73.   205,  0,  255,  255,
  74.   206,  0,  0,  255,      //blue
  75.   255,  0,  0,  255};
  76.  
  77. const TProgmemPalette16 redyell_p PROGMEM = {
  78.      0,    0, 0, 0,
  79.     120,    240,0,0,
  80.     235,    255,  200,  0,
  81.     255,    255,255,255};
  82.  
  83. CRGBPalette16 currentPalette(CRGB::Black);
  84. CRGBPalette16 targetPalette(CRGB::Black);
  85.  
  86. void setup() {
  87.    // Initialize LEDs
  88.    FastLED.setMaxPowerInVoltsAndMilliamps(5,LEDamps); //play with the order here
  89.    //FastLED.setTemperature();
  90.    FastLED.setBrightness(LEDbright);
  91.    FastLED.setDither(LEDdither);
  92.    FastLED.addLeds<LEDtype, PIN_C4, GRB>(leds[0], LEDper).setCorrection(LEDcorr);
  93.    FastLED.addLeds<LEDtype, PIN_C3, GRB>(leds[1], LEDper).setCorrection(LEDcorr);
  94.    FastLED.addLeds<LEDtype, PIN_C2, GRB>(leds[2], LEDper).setCorrection(LEDcorr);
  95.    FastLED.addLeds<LEDtype, PIN_C1, GRB>(leds[3], LEDper).setCorrection(LEDcorr);
  96.    FastLED.addLeds<LEDtype, PIN_C0, GRB>(leds[4], LEDper).setCorrection(LEDcorr);
  97.    FastLED.addLeds<LEDtype, PIN_E1, GRB>(leds[5], LEDper).setCorrection(LEDcorr);
  98.    FastLED.addLeds<LEDtype, PIN_E0, GRB>(leds[6], LEDper).setCorrection(LEDcorr);
  99.    FastLED.addLeds<LEDtype, PIN_D7, GRB>(leds[7], LEDper).setCorrection(LEDcorr);
  100.    FastLED.addLeds<LEDtype, PIN_D6, GRB>(leds[8], LEDper).setCorrection(LEDcorr);
  101.    FastLED.addLeds<LEDtype, PIN_D5, GRB>(leds[9], LEDper).setCorrection(LEDcorr);
  102.    FastLED.addLeds<LEDtype, PIN_D4, GRB>(leds[10], LEDper).setCorrection(LEDcorr);
  103.    FastLED.addLeds<LEDtype, PIN_D1, GRB>(leds[11], LEDper).setCorrection(LEDcorr);
  104.    FastLED.addLeds<LEDtype, PIN_D0, GRB>(leds[12], LEDper).setCorrection(LEDcorr);
  105.    FastLED.addLeds<LEDtype, PIN_B7, GRB>(leds[13], LEDper).setCorrection(LEDcorr);
  106.    FastLED.addLeds<LEDtype, PIN_B4, GRB>(leds[14], LEDper).setCorrection(LEDcorr);
  107.    FastLED.addLeds<LEDtype, PIN_B3, GRB>(leds[15], LEDper).setCorrection(LEDcorr);
  108.    FastLED.addLeds<LEDtype, PIN_B2, GRB>(leds[16], LEDper).setCorrection(LEDcorr);
  109.    FastLED.addLeds<LEDtype, PIN_B1, GRB>(leds[17], LEDper).setCorrection(LEDcorr);
  110.    FastLED.addLeds<LEDtype, PIN_B0, GRB>(leds[18], LEDper).setCorrection(LEDcorr);
  111.    FastLED.addLeds<LEDtype, PIN_E7, GRB>(leds[19], LEDper).setCorrection(LEDcorr);
  112.    FastLED.addLeds<LEDtype, PIN_E6, GRB>(leds[20], LEDper).setCorrection(LEDcorr);
  113.    FastLED.addLeds<LEDtype, PIN_F0, GRB>(leds[21], LEDper).setCorrection(LEDcorr);
  114.    FastLED.addLeds<LEDtype, PIN_F1, GRB>(leds[22], LEDper).setCorrection(LEDcorr);
  115.    FastLED.addLeds<LEDtype, PIN_F2, GRB>(leds[23], LEDper).setCorrection(LEDcorr);
  116.    FastLED.addLeds<LEDtype, PIN_F3, GRB>(leds[24], LEDper).setCorrection(LEDcorr);
  117.    FastLED.addLeds<LEDtype, PIN_F4, GRB>(leds[25], LEDper).setCorrection(LEDcorr);
  118.    FastLED.addLeds<LEDtype, PIN_F5, GRB>(leds[26], LEDper).setCorrection(LEDcorr);
  119.    FastLED.addLeds<LEDtype, PIN_F6, GRB>(leds[27], LEDper).setCorrection(LEDcorr);
  120.    FastLED.clear();
  121.    FastLED.show();
  122.  
  123.    Serial.begin(9600);
  124. }
  125.  
  126. void loop() {
  127.  
  128.   fillleds();
  129.  
  130.   if(palshuffle == true){
  131.     nblendPaletteTowardPalette( currentPalette, targetPalette, blendspeed);
  132.     nblendPaletteTowardPalette( currentPalette, targetPalette, blendspeed);
  133.   } else {
  134.     currentPalette = targetPalette;
  135.   }
  136.   if(palshuffle == true){
  137.     EVERY_N_SECONDS(10){
  138.       palettetargeting(random8(17));
  139.     }
  140.   }
  141.  
  142.   EVERY_N_SECONDS(10){
  143.     Serial.print("FPS: ");
  144.     Serial.print(LEDS.getFPS());
  145.     Serial.print(" Target: ");
  146.     //Serial.print(paltarget);
  147.     Serial.println();
  148.   }
  149.   //hue++;
  150.   FastLED.show();
  151. }
  152.  
  153. void fillleds(){
  154.   if(palshuffle == false){
  155.     palettetargeting(8);
  156.   }
  157.   CRGBPalette16 palette = redyell_p;
  158.   for(uint8_t x = 0; x < LEDstrips; x++){
  159.     for(uint8_t y = 0; y < LEDper; y++){
  160.       leds[x][y] = ColorFromPalette(palette, hue + y*8, 255, LINEARBLEND);
  161.     }
  162.   }
  163. }
  164.  
  165. void palettetargeting(uint8_t paltarget){      // Select which palette to blend to
  166.   switch(paltarget){
  167.     case 0:
  168.       targetPalette = startup;
  169.       break;
  170.     case 1:
  171.       targetPalette = purplecascade;
  172.       break;
  173.     case 2:
  174.       targetPalette = blackwhite;
  175.       break;
  176.     case 3:
  177.       targetPalette = newspaper;
  178.       break;
  179.     case 4:
  180.       targetPalette = sunburst;
  181.       break;
  182.     case 5:
  183.       targetPalette = gilt;
  184.       break;
  185.     case 6:
  186.       targetPalette = tropicana;
  187.       break;
  188.     case 7:
  189.       targetPalette = borderrainbow;
  190.       break;
  191.     case 8:
  192.       targetPalette = redyell_p;
  193.       break;
  194.     case 9:
  195.       targetPalette = RainbowColors_p;
  196.       break;
  197.     case 10:
  198.       targetPalette = RainbowStripeColors_p;
  199.       break;
  200.     case 11:
  201.       targetPalette = CloudColors_p;
  202.       break;
  203.     case 12:
  204.       targetPalette = PartyColors_p;
  205.       break;
  206.     case 13:
  207.       targetPalette = LavaColors_p;
  208.       break;
  209.     case 14:
  210.       targetPalette = OceanColors_p;
  211.       break;
  212.     case 15:
  213.       targetPalette = ForestColors_p;
  214.       break;
  215.     case 16:
  216.       targetPalette = HeatColors_p;
  217.       break;  
  218.   }
  219. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement