I Just ran into some problems with my LED code. I wanted to make it embedded, so store all of the animations on board but the controller keeps resetting since I added the last animation. I narrowed it down and figured it’s a matter of RAM. But atm I really only have one animation and some logic for handling ethernet connections.
So the question here would be if someone has an idea whats going wrong here(I’ll have a link to download the .ino at the end) or how you store your different animations and then trigger them.
Thanks in advance!
Here you go: http://www.file-upload.net/download-9603653/LEDserver2.zip.html (Arduino uno R3)
http://www.file-upload.net/download-9603647/LEDserver2.zip.html
There’s 5 ino files in here, which one is the one that’s giving you problems?
ah, nevermind, I see how you’re structuring it (I’m used to people naming the non-primary files .c/.cpp instead of .ino)
I just added another tab within the arduino IDE and thats what I got.
The blocks animation is the one I just added. it doesn’t really work the way I intended it just yet but if you were to extend the blockCounting array to like 4 cases it already crashes for me.
animationGlam is going to add 924 bytes of ram usage (doubles are 8 bytes each, and you’ve defined NUM_LEDS to be 60). Your leds are going to use 180 bytes of ram and then you have another 180 bytes used by ledDraft. So now you’re up to 1280 bytes of ram. The strings that you’re using in Serial.print statements are also going to be in ram, and there’s another ~200 bytes there, now you’re at 1480 bytes of ram. This isn’t including any memory/buffer overhead incurred by either the Serial class or the Ethernet classes.
Some immediate advice:
- change LEDaction to an array of bytes - that will save you 60 bytes
- change your LEDAlpha array to float instead of double, that will save you 240 bytes
- timerMax is set to only 100, you change change LEDtimer to “byte LEDtimer[NUM_LEDS];” and save another 180 bytes.
In all, the above should save you 480 bytes - which is nearly 25% of the ram the arduino uno has available to it 
(you can probably switch over to using integer math w/LEDAlpha and save another 120-180 bytes - but that’s beyond the scope of this quick rundown)
Wow, okay I really got to rethink my usage of variables. I’ve never really payed attention to data types since I’ve been only coding in c# on windows and there it didn’t really matter so far.
Other than that, what do you think of the way I trigger animations? Anything to improve here?
In the demo color palette sketch, in your examples folder that came with the library, @Mark_Kriegsman wrote a handy timing function called void ChangePalettePeriodically(). In that code I have adapted it to increment various things related to time.
A button on the other hand is quite easy when you use a switch case statement. Upon a button press, increment the variable in your switch statement:
void loop(){
if(buttonRead == HIGH){ menu++:}
switch(menu){
case 0: rainbow(); break;
case 1: cylon(); break;
}
}
@Jon_Burroughs I love that ChangePalettePeriodically() routine and am changing all my code to be able to support it. Trashing some routines, re-writing others and so on.
Is there documentation about that?
@Patrik_Nefuek Its not a feature of FastLED, rather something from a demo sketch: http://pastebin.com/nXWMuPBW
That being said, it’s an awesome demo loop for a single display routine (with changeable variables). If you have multiple display routines, then not so good, but that’s easily remedied.
@Andrew_Tuline I mainly use it as a global hue modifier. Every 5 seconds hue++, and every minute that passes minutes_timer++ for changing animations based upon minutes passed.