arduino remembers last state after power is off

Let's say I have 4 functions (A,B,C,D) and the power goes off. Is there a way to "remember" which function was occuring and "restart" from there when the power goes On again?


You can log the entry and exit of each function into EEPROM. When you restart you simply read EEPROM to determine the last function executed.

A potential issue with this approach is wearing out the EEPROM, they are good for around 100,000 write cycles and will eventually wear out. Keep EEPROM wear in mind when designing your algorithm.