Go Down

Topic: EEprom storage using writeAnything.h (Read 1 time) previous topic - next topic

SouthernAtHeart

Code: [Select]
struct config_settings {
    int mySensVals[13];  //# of pulses in 2-12 cups
    int motor_delay;     //change the distance the platform travels
    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 to turn on the cabinet lighting
    int Photocell_Level;  //threshold for light/darkness
} MySettings;

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

void SaveSettings(){
  EEPROM_writeAnything(0, MySettings);  //save the settings
  sendMessage("Settings saved!");
}


...so I think I'm using 33 bytes of EEPROM to save settings.
Now I have other settings I want to save/load in reference to time, since I've added an RTC module.
Can I save other settings to another part of the EEPROM like this:
Code: [Select]
struct config_settings {
    int CurrentYear;    //for keeping track of what year it is
    int CupsTotal;    //lifetime total
    int CupsMonth;    //cups drank this month
    int CusYear;        //cups drank this year
    int CupsLast;    //last cup drank
} TimeData;

void LoadSettings(){
  EEPROM_readAnything(34, TimeData);   //load the settings
}

void SaveSettings(){
  EEPROM_writeAnything(34, TimeData);  //save the settings
}


PaulS

Quote
Can I save other settings to another part of the EEPROM like this:

Yes, and no. You have the right idea, and address, but this:
Code: [Select]
struct config_settings {
    int CurrentYear;    //for keeping track of what year it is
    int CupsTotal;    //lifetime total
    int CupsMonth;    //cups drank this month
    int CusYear;        //cups drank this year
    int CupsLast;    //last cup drank
} TimeData;

won't work, because you have already defined a struct called config_settings, so you can't define another struct with the same name.

Code: [Select]
    int CusYear;        //cups drank this year
CusYear? No p?

SouthernAtHeart


Code: [Select]
    int CusYear;        //cups drank this year
CusYear? No p?


Ok, maybe it'd be better with a p.
:smiley-red:

Thanks, I didn't think about the first part of that struct, since I never use the name 'config_settings', I thought it was just part of the code that made the whole thing work.  So it can be anything?

PaulS

Quote
So it can be anything?

Well, there are a few reserved keywords that it CAN'T be, but everything else is what it CAN be.

Go Up