Using button to clear eeprom [solved]

Hi all,

I'm currently working on a project which is the wireless energy meter. Right now, i've to add a pushbutton to clear memory - writing "0" to the bytes in eeprom, clear the lcd and set values back to zero before it starts counting the energy consumption again, but it should not reset the whole arduino programming. I'm aware of the sketch for eeprom.clear but now, i've to combine program for the pushbutton and eeprom.clear and i've no idea how to start it. I'm using digital pin 8 for the button. Here's my programming i've done so far for the wireless energy meter. Please help, thank you.

Rachel K

My_Programming.ino (4.33 KB)

I don't really see the problem. In the loop() function read the pin that the button is attached to and if the button is pressed use a for loop to fill the EEPROM with zeroes. Am I missing something ?

clearing the eeprom is writing and as eeproms have limited (100K ?) write cycles.

Note: the factory default EEPROM value = 255 / 0xFF

Or just use 1 location to indicate if the others have valid data, or not.
If no valid data, sketch doesn't access them (i.e. it is cleared).
If it is valid data, allow reading.

UKHeliBob:
if the button is pressed use a for loop to fill the EEPROM with zeroes. Am I missing something ?

I would say if the button changes from not pressed to pressed, and the EEPROM is not already cleared, ...

It would be easy to wear out the EEPROM by repeatedly erasing it.

Peter, you are of course right and that is what I meant but did not express clearly. Combining that with CrossRoads suggestion of using one location as a clear/not clear flag would further reduce the chance of writing to the EEPROM when not necessary.

Hi,

Really thanks everyone for the suggestions. I've managed to write out the program and clear the eeprom with pushbutton. Thanks again (: