Hello, I would like to add more functionality to the Demo Reel 100 example

Hello, I would like to add more functionality to the Demo Reel 100 example by adding a momentary toggle switch (ON/OFF/ON, springing back to OFF) that lets the viewer scroll through patterns. This would be in place of the timer which calls nextpattern() every “N” seconds. I’ve got the switch working great with the button library and the UP/Down example. The only thing I’m missing is how to use the size of the pattern array.
I understand how the modulo operator (%) uses the remainder to loop from the maximum array size back to zero when increasing to the next pattern using function nextpattern(). I tried creating another function called prevpattern(), but I’m having trouble decrementing from zero to the array size of the patterns variable. In my example, I have six patterns, so I would like it to decrement from zero to 5.
in my “non-smart” way of coding it, when I call prevpattern() I can test if the pattern number is zero and shove a 5 in there but I would like to make it so I can just add/remove patterns without changing this prevpattern() function.
Thanks in advance!

Platform: Arduino NANO
IDE: Arduino IDE 1.6.7
FastLED Version 3.1 (the latest one from last night)
Code: http://hastebin.com/levupapanu.erlang_repl

Welcome, and it looks like you’re on the right track.

There’s a “C” idiom for figuring out how big an array is that looks like this:

int count = sizeof(array) / sizeof(array[0]);

So if you have an array of two-byte objects (like function pointers, in this case), and the array is ten bytes long, then it works out to:

int count = 10 / 2; // which equals “5”

There’s a macro in the code that does this for you, called ARRAY_SIZE. Use it like this:

if( patternNumber > 0) {
patternNumber = patternNumber - 1;
} else {
patternNumber = ARRAY_SIZE(gPatterns) - 1;
}

The “- 1” is needed because the array size will be, lets say, 5, which means that the highest pattern number will be 4.

That help?

Yes, that helps, thank you! Last night I was trying to use ARRAY_SIZE, but neglected the “-1” so the program was crashing when trying to go to a pattern number that was too high.
Thanks again.