ChibiM, to answer your questions earlier… The “noinit” thing basically means that a variable will not be set to 0 when the MCU receives power. Instead, it will be left in whatever state it was in before.

This is useful for measuring short vs long offtime because it takes about half a second for the MCU’s RAM to lose its contents after power is disconnected.

To use this trick you just set a “noinit” variable to a known value (0 works well since it usually decays to 1s) and then check it again at boot. If it’s still 0, you know the power must not have been off for very long. If it’s non-zero, the memory has already decayed and you can assume the power was off for a while. Use this to determine whether to go to the next mode or go back to the first mode.

Additionally, if you want it to always start at the same mode, there is no need to store anything in eeprom. Just store the current mode in a “noinit” variable and reset it to zero on short-press. This can make things even simpler than the code DrJones posted above.

Sleep mode can be used to optimize power a bit, but the difference in power is pretty tiny (less than 0.3mA) compared to the amount used to drive the LED (~5mA to ~3000mA, generally). Also, the MCU can’t go completely into sleep mode or the PWM counter will stop.