I have a need to store value from 0-5000 when the power is turned off on my arduino. This really needs to be stored with an accuracy of 1 (I cannot map it down and then map it back up again).
This also cannot be done on a microSD card or similar, I need to do it in eeprom.I thougt about storing each chracter seperately and then multiplying them and adding them together but because of the range of values, I don't think I can do this...
0-5000 fits easily into an "int" (aka "short", aka "int16" or two bytes).
What's the problem?
You cannot store int values in the EEPROM...
What is wrong with
// save value
int a = value/256;
int b = value % 256;
EEPROM.write(0,a);
EEPROM.write(1,b);
// read value
int a=EEPROM.read(0);
int b=EEPROM.read(1);
value = a*256+b;
You can store bytes in the EEPROM (range 0-255) so your value could be as high as 65535
Well, 8 bits.. which can be 0 or 1, and 8 bits equals... well, one byte!
lol.
But the EEPROM on board will work with higher numbers, but if you're working with some external EEPROM, well, that requires breaking down of bytes and sending them separately.
But the EEPROM on board will work with higher numbers, but if you're working with some external EEPROM, well, that requires breaking down of bytes and sending them separately.
Ok, so for on board EEPROM you can store bigger numbers simply but for external EEPROM it has to be broken down.