Yes you could (within reason as you have a limited number of writes) use the eeprom as non volatile storage. Put and get functions would let you store or access a structure
Although the EEPROM does have a limited number of write cycles, the 'suggested' maximum of 100,000 is a very conservative value.
I once did a test on an Arduino Uno R3, where I alternately wrote b01010101 and b10101010 to an EEPROM location. I then read the location to check whether the data had been written/read correctly.
I got up to over 5.3 million write cycles before an error occured. I realise that this was only a sample of 1 device, and there will be considerable variations in life expectancy.
this is a plain old nano - I understand that I have a limited number of writes and memory.
I have 0-7 buttons and a stepper motor - each button will represent the number of steps from point zero, when each button is positioned i would like to use a 9th button to save the step readings for each button. Once these are set they would most likely be readonly.
ie
button 4 has positioned the stepper to 140 steps from zero - we press button 9 and the index 4 writes the number of steps.
on setup these values are read for all buttons placed in an array.
this would change the structure of my data to
index
code (H or T)
steps
As you have been advised, you can dream up any use for EEPROM data storage, subject to constraints of size, speed of access and lifetime reliability.
Here I would suggest a small change
byte myRead(int address) {
// read a byte from the current address of the EEPROM
byte value = EEPROM.read(address);
Serial.print(address);
Serial.print("\t");
Serial.print(value, DEC);
Serial.println();
return value;
}
As you wrote it, there was no ability to use what got read. A temptation to make value global in scope should be resisted.
Also, myClear() is a nice idea; it might make more sense to avoid having a need to ever clear the entire EEPROM, just to reduce wear and tear.
the stepper motor is moved forward one step by buttons 3 and backward by button 4 when the stepper is in the required position button 9 latching button would be pressed and button 4 momentary this would write to index 4 -eeprom the stepper position (index 4 being the target position of button 4).
let me know if this is clear?
On a lot of devices, the default "erased" condition of EEPROM is all 1's (0xFF in each byte), not all 0's, so clearing the EEPROM to all 0's is wasting a write cycle. It would also be better to use update() instead of write(), otherwise a byte that already contains 0x00 will be erased to 0xFF then re-written to 0x00.
I don't think it would compile; if it does compile it is not likely to do what you think or want.
EEPROM at this level is fairly primitive. update() takes two arguments, a memory address and a byte of data, 8 bits. Checks to see and if need be actually writes the byte to memory.
Anything more sophisticated is kinda up to you to design and organize. There are a few more powerful functions, see
The first four lines are storing integers, which are two bytes each, but you are only allowing space for one byte. The last line is storing "Done", which is a char array that takes five bytes of storage, overwriting all the integers.