Go Down

Topic: Using the writeAnything utility without struct (Read 1 time) previous topic - next topic

SouthernAtHeart

This is currently what I have.  I like to have more than one struct value so as to keep things organized in my mind:
Code: [Select]
struct config_settings { //these are stored in EEPROM @ 50
  int accel;  //(516 orginally) Offset for the accelerometer when setting level
  int gyro;   //(467 orginally) Offset for the gyro when setting level
}
offset;

struct config_steering { //these are stored in EEPROM @ 25
  int center; //the value of the steering potentiometer in the center position
}
steering;


So then I can refer to them like:
Code: [Select]
steering.center
...or
offset.gyro


my question is: Since I only have one variable in the struct called steering, can I skip the struct, and just use a normal variable, like "steeringVal", and yet still use the writeAnything utility to save it to memory.  I currently do this:
Code: [Select]
  EEPROM_writeAnything(25, steering);  //save the steering settings to EEPROM @ 25


Could I skip the struct thing and just do this?
Code: [Select]
int steeringVal = analogRead(steeringPin);
EEPROM_writeAnything(25, steeringVal);  //save the steering settings to EEPROM @ 25


robtillaart


A small test sketch should show if it works or not. Just do one write/read in setup so it is executed only once.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Krodal

I think it is not good programming to use two different structures at fixed EEPROM locations.

You can use normal variables at fixed locations, but since you are using structures, you can also organize the structure in the way you like. You could make for example make a new structure that contains the two other structures.

robtillaart

Quote
I think it is not good programming to use two different structures at fixed EEPROM locations.

depends 100% on the sketch but it is seldom seen .. (EEPROM version of a union?)
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

SouthernAtHeart

Thanks. The writeAnything call works with just an int variable!  I tested it out in the setup, so it wouldn't run repeatedly.

fbriggs4

I have used it with individual variables and it works fine. You just need to make sure not to put 2 variables at the same EEPROM address and you have to space the address far enough apart to not step on each other. But otherwise it works fine.

Go Up