Guest User

Problem with FastLED.show()

a guest
Jul 13th, 2018
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 12.41 KB | None | 0 0
  1. #define USE_OCTOWS2811
  2. #include<OctoWS2811.h>
  3. #include<FastLED.h>
  4. #include <SLIPEncodedSerial.h>
  5. #include <OSCMessage.h>
  6.  
  7. String readString;
  8.  
  9. // FastLED provides these pre-conigured incandescent color profiles:
  10. //     Candle, Tungsten40W, Tungsten100W, Halogen, CarbonArc,
  11. //     HighNoonSun, DirectSunlight, OvercastSky, ClearBlueSky,
  12. // FastLED provides these pre-configured gaseous-light color profiles:
  13. //     WarmFluorescent, StandardFluorescent, CoolWhiteFluorescent,
  14. //     FullSpectrumFluorescent, GrowLightFluorescent, BlackLightFluorescent,
  15. //     MercuryVapor, SodiumVapor, MetalHalide, HighPressureSodium,
  16. // FastLED also provides an "Uncorrected temperature" profile
  17. //    UncorrectedTemperature;
  18.  
  19. #define TEMPERATURE UncorrectedTemperature
  20.  
  21. #define NUM_LEDS_PER_STRIP 203
  22. #define NUM_STRIPS 8
  23. #define BRIGHTNESS 255
  24. CRGB leds[NUM_STRIPS * NUM_LEDS_PER_STRIP];
  25.  
  26. SLIPEncodedSerial SLIPSerial(Serial1);
  27. enum pattern { NONE, BLOOMING, ENOGEN, TWINKLING, BLOOMING_RAINBOW, RAINBOW_THEATER_CHASE};
  28. enum mode { BLOMST, VU_METER, STREAM };
  29. enum direction { FORWARD, REVERSE };
  30.  
  31. //LED-strip order
  32. const uint8_t blomst1BunnHullStart = 0;
  33. const uint8_t blomst1ToppHullStart = 1;
  34. const uint8_t blomst1BunnOmrissStart = 2;
  35. const uint8_t blomst1ToppOmrissStart = 3;
  36.  
  37. const uint8_t blomst2BunnHullStart = 4;
  38. const uint8_t blomst2ToppHullStart = 5;
  39. const uint8_t blomst2BunnOmrissStart = 6;
  40. const uint8_t blomst2ToppOmrissStart = 7;
  41.  
  42. //Forklaring paa nivaaer i arrayene
  43. //0 = Faktisk index i leds[] arrayen
  44. //1 = Rekkefolge i blooming-animasjonen
  45. //2 = Stilk eller blomst
  46. //3 = Next random blink time
  47. //4 = Index pr LED for hvor den er i random blinkanimasjon
  48. float blomst1Omriss [5][377];
  49. float blomst1Hull [5][290];
  50. float blomst2Omriss [5][377];
  51. float blomst2Hull [5][290];
  52.  
  53. //Distanse mellom pixler i blomstene
  54. float distanse1 = 1.5;
  55. //startpixel for venstre blomst, bunn
  56. float vb_b = 31.0;
  57. //startpixel for hoyre blomst, bunn
  58. float hb_b = 35.0;
  59. float bunnHullRekkefolge [] = { 0.0,1.0,2.0,3.0,4.0,4.0,5.0,5.0,6.0,6.0,7.0,7.0,8.0,8.0,9.0,9.0,10.0,11.0,10.0,11.0,12.0,13.0,12.5,13.5,14.0,16.0,15.0,17.0,18.0,19.0,20.0,21.0,22.0,23.0,24.0,25.0,26.0,27.0, //Stilk
  60.                     vb_b+(2*distanse1),vb_b+(2*distanse1),vb_b+(3*distanse1),vb_b+(2*distanse1),vb_b+(3*distanse1),vb_b+(2*distanse1),vb_b+(3*distanse1),vb_b+(3*distanse1),vb_b+(1*distanse1),vb_b+(1*distanse1),vb_b+(1*distanse1),vb_b+(3*distanse1), //Blomst venstre
  61.                     28.0,28.0, //Stilk
  62.                     vb_b+(2*distanse1),vb_b+(1*distanse1),vb_b,vb_b+(1*distanse1),vb_b+(1*distanse1),vb_b+(2*distanse1),vb_b+(3*distanse1),vb_b+(2*distanse1),vb_b+(3*distanse1),vb_b+(3*distanse1), //Blomst venstre
  63.                     29.0,29.0,30.0,31.0,32.0,33.0, //Stilk
  64.                     hb_b+(2*distanse1), //Blomst hoyre
  65.                     32.0, //Stilk
  66.                     hb_b+(2*distanse1),hb_b+(2*distanse1),hb_b+(1*distanse1),hb_b+(1*distanse1), //Blomst hoyre
  67.                     33.0, //Stilk
  68.                     hb_b+(2*distanse1),hb_b+(2*distanse1),hb_b+(1*distanse1),hb_b+(1*distanse1),hb_b+(2*distanse1),hb_b+(2*distanse1),hb_b+(1*distanse1),hb_b,hb_b+(1*distanse1),hb_b+(2*distanse1),hb_b+(2*distanse1),hb_b+(2*distanse1) //Blomst hoyre
  69.                     };
  70.  
  71. //Distanse mellom pixler i blomst
  72. float distanse2 = 1.5;
  73. //startpixel for blomst1, topp
  74. float b1_t = 37.0;
  75. //startpixel for blomst2, topp
  76. float b2_t = 56.0;
  77. //startpixel for blomst3, topp
  78. float b3_t = 60.5;
  79. //startpixel for blomst4, topp
  80. float b4_t = 61.5;
  81.  
  82. float toppHullRekkefolge [] = {
  83.   //Stilk
  84.   34,34,
  85.   //Blomst1
  86.   b1_t+(5.5*distanse2),b1_t+(5.5*distanse2),b1_t+(5.5*distanse2),b1_t+(5.0*distanse2),b1_t+(3.0*distanse2),b1_t+(4.0*distanse2),b1_t+(5.0*distanse2),b1_t+(5.5*distanse2),b1_t+(5.5*distanse2),
  87.   b1_t+(5.5*distanse2),b1_t+(5.5*distanse2),b1_t+(5.0*distanse2),b1_t+(4.0*distanse2),b1_t+(5.0*distanse2),b1_t+(5.5*distanse2),b1_t+(5.5*distanse2),b1_t+(5.5*distanse2),b1_t+(5.5*distanse2),
  88.   b1_t+(5.0*distanse2),b1_t+(5.5*distanse2),b1_t+(5.0*distanse2),b1_t+(4.0*distanse2),b1_t+(3.0*distanse2),b1_t+(2.0*distanse2),b1_t+(2.0*distanse2),b1_t+(2.0*distanse2),b1_t+(2.0*distanse2),
  89.   b1_t+(2.0*distanse2),b1_t+(2.0*distanse2),b1_t+(2.0*distanse2),b1_t+(2.0*distanse2),b1_t+(3.0*distanse2),b1_t+(5.5*distanse2),b1_t+(5.0*distanse2),b1_t+(4.0*distanse2),b1_t+(5.0*distanse2),
  90.   b1_t+(5.5*distanse2),b1_t+(5.5*distanse2),b1_t+(5.5*distanse2),b1_t+(5.5*distanse2),b1_t+(5.0*distanse2),b1_t+(3.0*distanse2),b1_t+(4.0*distanse2),b1_t+(5.0*distanse2),b1_t+(5.5*distanse2),
  91.   b1_t+(5.5*distanse2),b1_t+(5.5*distanse2),b1_t+(5.0*distanse2),b1_t+(3.0*distanse2),b1_t+(2.0*distanse2),b1_t+(1.0*distanse2),b1_t+(1.0*distanse2),b1_t+(1.0*distanse2),b1_t,
  92.   b1_t+(1.0*distanse2),b1_t+(1.0*distanse2),b1_t+(1.0*distanse2),b1_t+(2.0*distanse2),b1_t+(2.0*distanse2),b1_t+(2.0*distanse2),b1_t+(4.0*distanse2),b1_t+(5.0*distanse2),b1_t+(5.5*distanse2),
  93.   b1_t+(5.5*distanse2),b1_t+(5.5*distanse2),
  94.   //Stilk
  95.   40,40.5,41.5,42.5,43,44,44.5,45.5,45.5,46.5,46.5,47.5,47.5,48.5,48.5,49.5,49.5,50.5,50.5,51,51.5,52,53,
  96.   //Blomst2
  97.   b2_t+(2.5*distanse1),b2_t+(2.5*distanse1),b2_t+(2.0*distanse1),b2_t+(2.5*distanse1),b2_t+(2.5*distanse1),b2_t+(2.0*distanse1),b2_t+(2.5*distanse1),b2_t+(1.0*distanse1),b2_t+(1.0*distanse1),
  98.   b2_t+(1.0*distanse1),b2_t,b2_t+(1.0*distanse1),b2_t+(1.0*distanse1),b2_t+(2.0*distanse1),b2_t+(2.5*distanse1),b2_t+(2.5*distanse1),b2_t+(2.0*distanse1),b2_t+(1.0*distanse1),
  99.   b2_t+(2.5*distanse1),b2_t+(2.5*distanse1),b2_t+(2.0*distanse1),b2_t+(2.5*distanse1),b2_t+(2.5*distanse1),
  100.   //Stilk
  101.   54,53,53,52.5,53.5,53.5,54.5,54.5,55.5,55.5,55.5,56.5,57.5,
  102.   //Blomst 3
  103.   b3_t+(2.5*distanse1),b3_t+(2.5*distanse1),b3_t+(2.5*distanse1),b3_t+(2.5*distanse1),b3_t+(2.5*distanse1),b3_t+(2.5*distanse1),b3_t+(2.0*distanse1),b3_t+(2.5*distanse1),b3_t+(1.0*distanse1),
  104.   b3_t+(1.0*distanse1),b3_t+(2.5*distanse1),b3_t+(2.0*distanse1),b3_t+(1.0*distanse1),b3_t,b3_t+(1.0*distanse1),b3_t+(1.0*distanse1),b3_t+(1.0*distanse1),b3_t+(2.5*distanse1),
  105.   b3_t+(2.5*distanse1),b3_t+(2.0*distanse1),b3_t+(2.5*distanse1),b3_t+(2.5*distanse1),b3_t+(2.0*distanse1),b3_t+(2.5*distanse1),b3_t+(2.5*distanse1),b3_t+(2.0*distanse1),
  106.   //Stilk
  107.   58.5,57.5,56.5,56.5,56.5,57.5,58.5,
  108.   //Blomst4
  109.   b4_t,b4_t+(1.0*distanse2),
  110.   //Stilk
  111.   59.5,
  112.   //Blomst4
  113.   b4_t+(2.0*distanse2),b4_t+(1.0*distanse2),b4_t+(3.0*distanse2),b4_t+(2.5*distanse2),b4_t+(4.0*distanse2),b4_t+(5.0*distanse2),b4_t+(3.0*distanse2),b4_t+(3.5*distanse2),b4_t+(5.0*distanse2),
  114.   b4_t+(5.5*distanse2),b4_t+(5.5*distanse2),b4_t+(5.5*distanse2),b4_t+(5.0*distanse2),b4_t+(5.5*distanse2),b4_t+(6.0*distanse2),b4_t+(6.5*distanse2),b4_t+(7.0*distanse2),b4_t+(7.0*distanse2),
  115.   b4_t+(6.5*distanse2),b4_t+(6.0*distanse2),b4_t+(5.5*distanse2),b4_t+(4.5*distanse2),b4_t+(2.5*distanse2),b4_t+(0.5*distanse2),b4_t+(1.5*distanse2),b4_t+(3.5*distanse2),b4_t+(5.5*distanse2),
  116.   b4_t+(5.7*distanse2),b4_t+(6.0*distanse2),b4_t+(6.5*distanse2),b4_t+(6.5*distanse2),b4_t+(6.0*distanse2),b4_t+(5.0*distanse2),b4_t+(4.5*distanse2),b4_t+(4.0*distanse2),b4_t+(3.0*distanse2),
  117.   //Stilk
  118.   60.5,59.5,58.5,58.0,57
  119. };
  120.  
  121.  
  122. class LedsMultitask
  123. {
  124.   public:
  125.  
  126.     pattern ActivePattern1;
  127.     mode ActiveMode;
  128.     direction Direction;
  129.     bool EndOfPattern;
  130.  
  131.     unsigned long Interval1;
  132.     unsigned long Interval2;
  133.     unsigned long lastUpdate1;
  134.     unsigned long lastUpdate2;
  135.  
  136.     uint8_t Hue1;
  137.     uint8_t Value1;
  138.     uint8_t Saturation1;
  139.     uint8_t Hue2;
  140.     uint8_t Value2;
  141.     uint8_t Saturation2;
  142.  
  143.     uint8_t IncrementSat;
  144.     uint8_t IncrementVal;
  145.  
  146.     float Delta;
  147.     float Index1;
  148.     float Increment_by1;
  149.     float Index2;
  150.     float Increment_by2;
  151.  
  152.     uint16_t TotalSteps1;
  153.     uint16_t TotalSteps2;
  154.  
  155.     uint8_t SegmentColorRed;
  156.     uint8_t SegmentColorGreen;
  157.     uint8_t SegmentColorBlue;
  158.     uint8_t NumberOfStrips;
  159.     uint8_t LedsPerStrip;
  160.     uint16_t Pixels;
  161.     boolean UpdatePattern;
  162.     boolean Flash;
  163.     boolean Dim;
  164.     uint8_t PixelDistance;
  165.     uint8_t PixelWidth;
  166.     uint8_t TailLength;
  167.  
  168.     uint32_t BlinkRandomTime;
  169.     uint32_t NextBlink_LEDi[NUM_LEDS_PER_STRIP * NUM_STRIPS];
  170.  
  171.  
  172.     LedsMultitask(mode displaymode)
  173.     {
  174.         Pixels = NUM_LEDS_PER_STRIP * NUM_STRIPS;
  175.         ActiveMode = displaymode;
  176.     }
  177.  
  178.     // Update the pattern (hull)
  179.     void Update1()
  180.     {
  181.       Serial.println("Update1");
  182.       if ((millis() - lastUpdate1) > Interval1) // time to update
  183.       {
  184.         lastUpdate1 = millis();
  185.         switch (ActivePattern1)
  186.         {
  187.           case BLOOMING_RAINBOW:
  188.               BloomingRainbowUpdate();
  189.               break;
  190.           default:
  191.             break;
  192.         }
  193.       }
  194.     }
  195.  
  196.     // Update the pattern (omriss)
  197.     void Update2()
  198.     {
  199.       if ((millis() - lastUpdate2) > Interval2) // time to update
  200.       {
  201.         lastUpdate2 = millis();
  202.         switch (ActivePattern1)
  203.         {
  204.           case BLOOMING_RAINBOW:
  205.             break;
  206.           default:
  207.             break;
  208.         }
  209.       }
  210.     }
  211.  
  212.  
  213.  
  214.     void ResetAllLEDs () {
  215.       for (int i = 0; i < NUM_STRIPS*NUM_LEDS_PER_STRIP; i++) {
  216.         leds[i] = CRGB::Black;
  217.       }
  218.     }
  219.  
  220.  
  221.  
  222.     // Increment the Index and reset at the end
  223.     void Increment(float *index, uint16_t *total_steps, float *increment_by)
  224.     {
  225.       *index = *index + *increment_by;
  226.  
  227.       if (*index >= *total_steps)
  228.       {
  229.         *index = 0;
  230.       }
  231.     }
  232.  
  233.     void BloomingRainbow()
  234.     {
  235.       //Hull
  236.       Interval1 = 30;
  237.       ActivePattern1 = BLOOMING_RAINBOW;
  238.       Value1 = 255;
  239.       Saturation1 = 255;
  240.       Saturation2 = 0;
  241.       TotalSteps1 = 100;
  242.       Index1 = 0;
  243.       Increment_by1 = 1;
  244.       Delta = 4;
  245.  
  246.       //Omriss
  247.  
  248.       //Zero all LEDs
  249.       ResetAllLEDs();
  250.       Serial.println("BloomingRainbow");
  251.     }
  252.  
  253.     void BloomingRainbowUpdate()
  254.     {
  255.       for (int x = 0; x < NUM_STRIPS*NUM_LEDS_PER_STRIP; x++)
  256.       {
  257.         leds[x] = CRGB::White;
  258.       }
  259.       Serial.println("BloomingRainbowUpdate");
  260.       FastLED.show();
  261.       Serial.println("BloomingRainbowUpdate2");
  262.     }
  263.  
  264. };
  265.  
  266. LedsMultitask Ledstrip(BLOMST);
  267.  
  268. void setup() {
  269.   Serial.begin(9600);         //Teensy <=> Computer
  270.   SLIPSerial.begin(115200);   //Teensy <=> ESP
  271.   delay(1000);
  272.   Serial.println("Started");
  273.  
  274.   FastLED.addLeds<OCTOWS2811>(leds, NUM_LEDS_PER_STRIP);
  275.   LedArrayMaker();
  276.   Ledstrip.BloomingRainbow();
  277. }
  278.  
  279. void loop() {
  280.   Serial.println("loop");
  281.   //OSCMsgReceive();
  282.   Ledstrip.Update1();
  283.   //Ledstrip.Update2();
  284. }
  285.  
  286.  
  287. void LedArrayMaker()
  288. {
  289.  
  290.  
  291.   //Hull bunn, begge blomster
  292.   for (int i = 0; i < 87; i++) {
  293.     blomst1Hull[0][i] = (blomst1BunnHullStart*NUM_LEDS_PER_STRIP)+i;
  294.     blomst2Hull[0][i] = (blomst2BunnHullStart*NUM_LEDS_PER_STRIP)+i;
  295.  
  296.     blomst1Hull[1][i] = bunnHullRekkefolge[i];
  297.     blomst2Hull[1][i] = bunnHullRekkefolge[i];
  298.  
  299.     //Definerer hva som er blomster
  300.     if ( ((i > 37) && (i < 50)) || ((i > 51) && (i < 62)) ) {
  301.       blomst1Hull[2][i] = 0;
  302.       blomst2Hull[2][i] = 0;
  303.     }
  304.     //Definerer hva som er blomster
  305.     else if ( (i==68) || ((i>69) && (i<74)) || ((i>74)&&(i<87)) ) {
  306.       blomst1Hull[2][i] = 0;
  307.       blomst2Hull[2][i] = 0;
  308.     }
  309.     //Definerer hva som er stilk
  310.     else {
  311.       blomst1Hull[2][i] = 1;
  312.       blomst2Hull[2][i] = 1;
  313.     }
  314.   }
  315.   //Hull topp, begge blomster
  316.   for (int i = 0; i < 203; i++) {
  317.     int x = 87 + i;
  318.  
  319.     blomst1Hull[0][x] = (blomst1ToppHullStart*NUM_LEDS_PER_STRIP)+i;
  320.     blomst2Hull[0][x] = (blomst2ToppHullStart*NUM_LEDS_PER_STRIP)+i;
  321.  
  322.     blomst1Hull[1][x] = toppHullRekkefolge[i];
  323.     blomst2Hull[1][x] = toppHullRekkefolge[i];
  324.  
  325.     //Definerer hva som er blomster
  326.     if ( ((x>88) && (x<154)) || ((x>176) && (x<200)) || ((x>212) && (x<239)) || ((x>245) && (x<248)) || ((x>248) && (x<285)) ) {
  327.       blomst1Hull[2][x] = 0;
  328.       blomst2Hull[2][x] = 0;
  329.     }
  330.     //Definerer hva som er stilk
  331.     else {
  332.       blomst1Hull[2][x] = 1;
  333.       blomst2Hull[2][x] = 1;
  334.     }
  335.   }
  336.  
  337.   //Omriss blomst1 bunn
  338.   for (int i = 0; i < 187; i++) {
  339.     blomst1Omriss[0][i] = (blomst1BunnOmrissStart*NUM_LEDS_PER_STRIP)+i;
  340.   }
  341.   //Omriss blomst1 topp
  342.   for (int i = 0; i < 189; i++) {
  343.     blomst1Omriss[0][i+188] = (blomst1ToppOmrissStart*NUM_LEDS_PER_STRIP)+i;
  344.   }
  345.   //Omriss blomst2 bunn
  346.   for (int i = 0; i < 187; i++) {
  347.     blomst2Omriss[0][i] = (blomst2BunnOmrissStart*NUM_LEDS_PER_STRIP)+i;
  348.   }
  349.   //Omriss blomst2 topp
  350.   for (int i = 0; i < 187; i++) {
  351.     blomst2Omriss[0][i+188] = (blomst2ToppOmrissStart*NUM_LEDS_PER_STRIP)+i;
  352.   }
  353. }
Advertisement
Add Comment
Please, Sign In to add comment