Finite State Machine Handling Timers Gracefully?
If you want super low tech "multitask" your timer interrupt can look like this:

timer_isr()
{
    process1();
    process2();
    process3();
}


So, if your timer fires, say, 100x per second then every time each process() function is called. These functions are FSMs which implement your different "multitasked" tasks. If they are all independent, then it's easy.

Now, if your tasks are dependent, you can do something like:

timer_isr()
{
    check_buttons();
    blink_red();
    blink_blue();
}


In this case the tasks will communicate via ugly global variables (we aint gonna do message boxes and FIFOs on a 8-bit are we). For example check_buttons() would debounce, etc, and set some flags and/or directly influence the state of the other two FSMs which blink the LEDs.

We can even use this bleeding edge tech called C++:

timer_isr()
{
    check_buttons();
    red.blink();
    blue.blink();
}


In this case check_buttons() would call "red.setBlinkMode( some value )" when the appropriate button is pressed, for example. "red" and "blue" are global objects. In this case this tiny bit of OO allows you to implement the same algo for both without having to mess with tons of globals, or pointers to structs, etc.

It is a nice thing to handle your buttons in only one place in your code. Especially if the buttons control several things, for example one button to select the LED, and another button to modify the blinking pattern of the selected LED.

The .blink() method would, for example, increment a LED-specific counter until it reaches the blinking period, or adjust a PWM in a time-dependent fashion to make it blink fancily, that kind of stuff.

For example, if your times is called ever millisecond, your blink() method could be:

LED::blink()
{
    if( led_on) {
        if( counter++ &gt; period ) {
            counter=0;
            led_pin = !led_pin;
        }
    } else { led_pin = 0; counter=0; }
}


...something like that. They're all called at the same timer period, so all these small state machines know about time by counting the number of times they are called. In this case the state of the FSM is led_on and counter.