Can someone please explain the code found here to me?
http://www.arduino.cc/playground/Code/E … teAnything
I want to store several numbers in the EEPROM but I have been unable to get it to work
I need it to store several numbers like this “41.914768218994140” and then be able to recall it.
I have been messing around with it for several hours without success.
If I comment out the writeanything and change the float lats value shouldn’t it recall the old value in the eeprom and display the old value?
#include <EEPROM.h>
template <class T> int EEPROM_writeAnything(int ee, const T& value)
{
const byte* p = (const byte*)(const void*)&value;
int i;
for (i = 0; i < sizeof(value); i++)
EEPROM.write(ee++, *p++);
return i;
}
template <class T> int EEPROM_readAnything(int ee, T& value)
{
byte* p = (byte*)(void*)&value;
int i;
for (i = 0; i < sizeof(value); i++)
*p++ = EEPROM.read(ee++);
return i;
}
struct config_t
{
float lats;
} configuration;
void setup()
{
Serial.begin(9600);
// ...
}
void loop()
{
float lats = 41.914768218994140;
EEPROM_readAnything(81, configuration);
EEPROM_writeAnything(81, configuration);
Serial.println(lats, 15);
delay(15000);
}