Pages: [1]   Go Down
Author Topic: Using the writeAnything utility without struct  (Read 1136 times)
0 Members and 1 Guest are viewing this topic.
South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 654
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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:
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:
  EEPROM_writeAnything(25, steering);  //save the steering settings to EEPROM @ 25

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

South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 654
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://playground.arduino.cc/Code/EEPROMWriteAnything
...sorry, I forgot to add this link to EEPROMWriteAnything
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13734
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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

Rob Tillaart

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

Offline Offline
Edison Member
*
Karma: 9
Posts: 1016
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13734
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?)
Logged

Rob Tillaart

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

South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 654
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Virginia, USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 93
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: