Hi, I've read multiple threads on different websites but I'm still a little stuck with this.
I am writing a program for an alarm, one of the functions allows the user to alter some values, based on the size of their fuel tank/fuel type. (tankw - width, tankl - length, weight - fuel density, warning - low level volume).
I want these values to be saved after setting, even if there is a power interruption, then loaded during the setup during restart.
Here is my function to update the values after the user goes through the function to set there values:
void setTank()
{
EEPROM.update(tankw,tankw); // write (tankw) to nonvolatile memory
EEPROM.update(tankl,tankl); // write (tankl) to nonvalatile memory
EEPROM.update(weight,weight); // write (weight) to nonvalatile memory
EEPROM.update(warning,warning);
}
shaunh84:
Here is my function to update the values after the user goes through the function to set there values:
void setTank()
{
EEPROM.update(tankw,tankw); // write (tankw) to nonvolatile memory
EEPROM.update(tankl,tankl); // write (tankl) to nonvalatile memory
EEPROM.update(weight,weight); // write (weight) to nonvalatile memory
EEPROM.update(warning,warning);
}
This is not going to do what you expect it to. As is explained in the EEPROM library reference: https://www.arduino.cc/en/Reference/EEPROMUpdate
the first parameter of EEPROM.update() is the EEPROM address. You need to define a specific address where each configuration is stored. Something like this:
unsigned int tankwAddress = 0;
unsigned int tanklAddress = 1;
... and so on
then:
EEPROM.update(tankwAddress, tankw); // write (tankw) to nonvolatile memory
EEPROM.update(tanklAddress, tankl); // write (tankl) to nonvolatile memory
Here is an example using put() and get() to store and save parameters in a struct. I used int data types in the struct but you can use any data type and even mix data types.
Thanks for the responses, I got there in the end, and until just now didn't know how to find old posts, and didnt realise there had been extra responses!
I used addresses to update and read from, had a little fun with numbers bigger than 255 but got there!