Go Down

Topic: Saving arrays in EEPROM using ARDUINOMEGA (Read 6 times) previous topic - next topic

AWOL

#10
Mar 09, 2011, 09:12 pm Last Edit: Mar 09, 2011, 09:15 pm by AWOL Reason: 1
Quote
It is saved as int....
int reference = 323;

But the EEPROM is only byte wide.

sizeof (byte) == sizeof (int) / 2  (for the Arduino)
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

PaulS

EEPROM.write() and EEPROM.read() operate on bytes. To save an int:

Code: [Select]
EEPROM.write(0, highByte(reference));
EEPROM.write(1, lowByte(reference));


To read an int:

Code: [Select]
int val = (EEPROM.read(0) << 8) + EEPROM.read(1);

You might want to look at the EEPROM_readAnything() and EEPROM_writeAnything() functions:
http://www.arduino.cc/playground/Code/EEPROMWriteAnything

Daniel Formosa

Ok didn't know this....
So I am using 2 addresses inside the EEPROM now?

That is a problem....

AWOL

#13
Mar 09, 2011, 09:26 pm Last Edit: Mar 09, 2011, 09:28 pm by AWOL Reason: 1
Quote
So I am using 2 addresses inside the EEPROM now?

So you've got at least 510 more to play with

That's not a problem - read and understand reply #11
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Daniel Formosa

No it is a problem...
The integer of the reference # varies from 322 to 500 (so in this case it the above procedure needs to be done, if I am correctly understanding)
While the gas # varies from 500 to 1200. Which means I am taking more than one and more addresses

But I need to save these #s in an array which is proportional to the reference # and gas

meaning array[reference] = gas

So how can I know which address it is if each refernce # and gas amount is different entered by the user??

I don't know If I described it correctly....

Go Up