Flash memory problems part 1
When I wanted to add animations to the led strips I ran into memory issues of the Arduino.
Today's programmers are spoiled. Computers have gotten so fast and advanced that you can throw more and more code at them. They used to send people to moon with 145 000 lines of code, now I guess that my refrigerator uses more code and has more memory then that computer. I had never thought this problem would occur, but when I wanted to put my animation arrays into a for loop in C++ I got a compile error:
I used 106% of my Arduino memory (51988 of 48640 bytes). When you code in JavaScripts your only limitations are your imagination, but now I was held back by the physical memory of my Arduino. Fortunately, there are a few possible solutions (as indicated in the console):
I went down this list, most of the solutions did not apply. Removing the print statements made little to no difference. The biggest difference was made by modifying the data types. By changing 'int' to 'byte' once in my 2D array, I was able to save as much as 5% (2.4KB) of my memory, which is relatively large. Byte is a much more compact data type I learned. A byte stores an 8-bit unsigned number, from 0 to 255. (versus minimum value of -2^15 and a maximum value of (2^15) - 1 for an int). Which was perfect because the LEDs in that case only went up to 249
By applying this technique in other places, I could eventually get to 99% of the total storage after compiling. But when I tested this, the Arduino became very unstable, especially when new messages came in from the database.
The arduino automatically restarted several times. Here I could not do anything with it. From experience and testing I learned that you must leave at least 10% of the memory as a margin, then everything went smoothly. The only way to achieve this was to get rid of long strings and (2D) arrays. I removed the array that took care of the mapping of numbers (from 0 to 9) and different led animations (incoming message, heart flies in and enlarges). In the end I was able to keep my sketch under 90% of the total flash memory, with a few tweaks and some unfortunate restrictions.