Pages: [1]   Go Down
Author Topic: eeprom settings with default  (Read 1728 times)
0 Members and 1 Guest are viewing this topic.
South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 647
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In the code below, how do I add a default value, so that if the settings are deleted from eeprom, a default value will be given?  I want these default values:
MySettings.lightLevel = 800
MySettings.motor_delay = 40

Code:
struct config_settings {
    int mySensVals[12];  //# of pulses in 2-12 cups
    int motor_delay;     //change the distance the platform travels
    int lightLevel;         //photocell trigger level
    boolean Enable_Audio;  //whether the user wants sound
    boolean Enable_Piezo;  //whether the user wants a knock sensor
    boolean Enable_PhotoCell;  //whether the user wants to use the photocell
} MySettings;

void LoadSettings(){
  EEPROM_readAnything(0, MySettings);   //load the settings
}

void SaveSettings(){
  EEPROM_writeAnything(0, MySettings);  //save the settings
}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 600
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
In the code below, how do I add a default value, so that if the settings are deleted from eeprom, a default value will be given?
How would they be deleted? If you don't provide code to delete what is in EEPROM, what is there is what you wrote last time.

If you want to ensure that data has been stored there before using what you read, you should add a char array to the structure, at the beginning. Test if what is read from the EEPROM is some specific value (your application's name, for instance). If so, use what is there. Otherwise, assign specific values to the variables.
Logged

Pages: [1]   Go Up
Jump to: