Hello,
I'm trying to control a strand of WS2811 LEDs using an Arduino MEGA. For this I wanted to write a library called OctagonPanel that makes use of the very handy FastLED library to create my own methods and because I want to control other hardware later on as well.
For this I followed the tutorial on how to write your own library and classes. After some tinkering I got it to work but here's the catch: when i call a certain method, namely "update()", (which ironically is the most important one) the Arduino slows down so much that one loop cycle takes like 1.5 seconds.
I found out that it could be heap fragmentation. I read that the use of pointers can greatly decrease the risk of this happening but in the same article it's stated that pointers and such should only be used when really necessary.
Maybe it's something completely different.
Attempting to google this situation only yielded me results on slow compilation.
Here's my main:
#include "src\FastLED\FastLED.h"
#include <HardwareSerial.h> // HardwareSerial muss mit eingebunden werden, da sonst mit VSC Serial nicht funktioniert
#include "src\LightingControl\OctagonPanel.h"
const unsigned int NUM_LEDS = 160;
const int DELAY = 10, DATA_PIN = 6, HUE = 40;
int ledDefinerArray[NUM_LEDS]{0,0,0,0,1,1,1,1,2,2,2,2,0,0,0,0};
OctagonPanel panel1(DATA_PIN, NUM_LEDS, ledDefinerArray);
void setup(){
Serial.begin(9600);
panel1.begin();
panel1.setHue(240);
panel1.setLevel(50);
panel1.testFunc();
}
void loop(){
panel1.update();
}
The library is attached to this post.
The program executes at normal speed up until the 98th of 100 iterations of the last for loop of testFunc and then it slows down incredibly.
Here's a little explanation of what the library should be doing:
There's the single LED strand which will be mounted to a wall and will go up the wall in sections either vertically, diagonally or move left or right horizontally to create a nice pattern. The strip is supposed to fill from the bottom to the top with a constant vertical speed. This means that the diagonal LEDs have to fill faster than the vertical ones and the horizontal ones need to fill up simultaneously. The array called "ledDefinerArray" defines what type of LED each LED is. The array "ledTypes" saves the necessary values for the three types. The first value is the amount of iterations needed to fill the LED and the second value states how many iterations of th ecurrent LED must have been passed to start filling the next LED. Based on these pieces of information the "update()" method is repeatedly called and gradually fills the Strip up to the wanted level (_levelTarget)
P.S: my variable declarations are a bit scattered as I've been fooling around with different data types and figured that this might've been the culprit. Sadly it wasn't.
Thank you in advance for your time!
Cheers
Smagel
OctagonPanel.cpp (4.21 KB)
OctagonPanel.h (857 Bytes)