Frequently Asked Questions
How do I write variables to EEPROM that are not a byte?
The following is an example of how to read and write a floating point number
from/to EEPROM. The same concept may be used for structures, arrays or any
other type.
- n is an offset into the eeprom.
- For example if the first float is at 0 the second
- For floats you must increment it by 4.
- one should be at 4 and the third at 8.
WRITE_FLOAT_EXT_EEPROM(long int n, float data) {
int i;
for (i = 0; i < 4; i++)
write_ext_eeprom(i + n, *((int8*)&data + i) ) ;
}
float READ_FLOAT_EXT_EEPROM(long int n) {
int i;
float data;
for (i = 0; i < 4; i++)
*((int8*)&data + i) = read_ext_eeprom(i + n);
return(data);
}