Go Down

Topic: How to retain the previous button state even after switching off the Arduino (Read 2187 times) previous topic - next topic


dochawk

Use EEPPROM.update(cell, value)

  It only updates the cell so the lifetime of a cell is increased.
Read location 0 for the address to use.
Update that address.
Read it back to insure success.
If the write failed, increment location 0 to the next cell and write where t tells you..

hawk

Grumpy_Mike

Quote
If the write failed,
That is not the normal failure mode. Normally when a cell fails it will continue to act as a memory location but will not retain the value through a power cycle. It is only when it gets way past that, you get a fail on a write.

From past experience Atmel were not very good at EEPROM anyway but that is another story.

Biscit42

this is to be connected a rotary system for every rotation there will be one click on the switch and Two entries in to the EPPROM, and the rotation is 20 RPM so 20 x 2 writing in to EEPROM.


The original post said the following

1. first press the blue light glows,
2. second press the yellow light glows for some time and changes to red.

Unless there is more happening than we have been told this would be a single 'state' variable with 3 possible values.
initially state=1 >>  blue led on
press gives state=2 >> yellow led on, blue off
timer elapsed state=3 >> red red on, yellow off
press >> state=1 ---------------etc.

To reset to the existing state as envisaged by the OP would need to write the state variable to EEPROM 3 times per cycle but only one variable.

Mike

Paul__B

I should perhaps point out that the OP (Original Poster) lost interest four days ago.  :smiley-roll:

Go Up