How can I reduce the memory usage on my code?
As well as PROGMEM (as described in the comments), there are a couple of other efficiencies that you can make:


A function call is expensive (takes a lot of code space), and you are performing a LOT of them!


The repetitious calls to delay() followed by treeFunc() are wasteful. Your commented-out line

//delay(arrayTimes[i]);


looks like you were going to do the right thing, so I’d restore that (use count instead of i) and put the delay() numbers in a new int arrayTimes[] array.

PROGMEM this array too, of course!
Once you’ve done this, you can remove all the calls to delay(). You’ll be left with nothing but repeated calls to treefunc(), which you can replace with a single loop:

for (count=0;count&lt;sizeof(arrayTree);++count) {
   treeFunc();
} // for


Don’t forget to get rid of the count = count + 1; line from treeFunc() - it’s now in the for loop.

Also expensive is calling the same function twice except with different parameters in both sides of the if in treeFunc(). Instead of:

if (&lt;condition&gt;) {
   Function(1);
} // if
else {
   Function(0);
} // else


you can instead do:

Function(&lt;condition&gt;);


For this to work, you need to know that HIGH has the value 1 and LOW has the value 0 - and that a true condition has the value 1 and a false condition has the value 0.

So, you need to change the if () slightly:

digitalWrite(THREEONE, (num%2)&gt;0);

Finally, the mod % operator itself is very expensive, since it is effectively a division, and the Arduino chip doesn’t know how to divide - so the code to do so is large. But the code you’ve written is using binary arithmetic, which the Arduino can do instantly - you just have to write it as such.


Instead of (num%2)&gt;0 use num &amp; B0001.
Instead of (num%4)&gt;1 use num &amp; B0010.
Instead of (num%8)&gt;3 use num &amp; B0100.
Instead of (num%16)&gt;7 use num &amp; B1000.



You’ve probably copied the guts of this code from somewhere else, and while it works it isn’t very efficient. Writing the code as above will greatly reduce your code size, exchanging repeated calls for much smaller PROGMEM arrays.