retaining the last state of a bit before and after powering the board?

I need to remember a bit set equal to one, if power is lost and regained to the arduino board.
Can this be done without adding a memory card that is externally powered, or will I need to add one?
Does the arduino have a last state function?
I did not see anything in the programming library that led me to believe this function exists?
Just wondering if anyone has an answer to this question?

The chips have onboard EEPROM - it's free and easy to use. Perfect for storing small amounts of state information.

Checkout EEPROM.h

Cheers,

Good point! I will look into the eprom functions and see if I can get it working. Thanks for the help!

Of course, you cant wait to store when power is lost - at that point it is too late. :open_mouth:

So you must store your state in EEPROM evey time it changes - just in case power fails. At which point a second problem makes itself felt:

These EEPROM can only be set a finite number of times (100.000) at which time they become unreliable. The same is true for your flash-ROM where the program is located (which only takes 10.000? writes). This only happens when you upload a new program so for most purposes it lasts a looong time.

When you have a sktech you're likely to write much more often, and then the EEPROM will only last you a few months.

Totally depends how often you write to the EEPROM - in many cases an EEPROM could last a very looong time - certainly longer than a few months.

Cheers,

One method, depending on how you power your board, is to build a early "power is going away" circuit that can then generate an interrupt signal which can write your state data into eeprom. Don't need much warning time but again it's about how you power the board. USB only power would be kind of difficult I would think, but monitoring the Vin pin with a voltage divider and maybe a big super cap to hold the voltage a little longer would be possible.

Lefty

I finished the code writting EEPROM address 0 high or low during each event, and then it is read during initialization. I tested it and it works great. Thanks for the input!