Go Down

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

Daniel Formosa

It is stored in address 0 1 and 2 i think.
Code: [Select]
#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;
void setup()
  int reference = 323;
  int serial;

  EEPROM_writeAnything(0, reference);
  serial = EEPROM.read(0) + EEPROM.read(1) + EEPROM.read(2);
void loop()

serial = EEPROM.read(0) + EEPROM.read(1) + EEPROM.read(2);
  Removing read(2) will not give 323


It is stored in address 0 1 and 2 i think

Think again.
"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

serial = EEPROM.read(0) + EEPROM.read(1) + EEPROM.read(2);
  This 'prints' 323

serial = EEPROM.read(0) + EEPROM.read(1)
This 'prints' 68

why then??
(And hehe i am on a laptop so shaking my keyboard wont make it that better :p)



The value is not stored digit by digit in consecutive addressed. I think you need to go back and look at reply #11 (not to sound like a broken record or anything).

Daniel Formosa

"You provide the first EEPROM address to be written, and the functions return how many bytes were transferred."
So if in this code it returns 2, meaning 2 bytes were transferred right?

But still I cannot understand the fact that using the code; EEPROM.read(0) + EEPROM.read(1) it 'prints' 68.

I'm sorry if im being such a bi*** but I really need to understand this

tnx again

Go Up