Thanks for the link, but will this work for writing 8 values? Sorry I'm a noob trying to learn.
Yes, using that function you can access any memory location in the eeprom. The eeprom is capable of holding 512 bytes, hence has 512 memory addresses ranging from 0 - 511.
I'm not writing a lot of data but values up to 1500 or so.
So let's say that you were using ints to store these values. Let's assume that you only have 3 values that you wish to write, a, b and c.
#include <EEPROM.h>
int a = 1500, b = 1600, c = 1700;
void setup()
{
int eeprom_address = 0; //We will start writing at the first memory address
eeprom_address += EEPROM_writeAnything(eeprom_address, a); //write a to memory and then updates eeprom address
eeprom_address += EEPROM_writeAnything(eeprom_address, b);
eeprom_address += EEPROM_writeAnything(eeprom_address, c);
}
void loop()
{
//nothing to loop as we only store these values into eeprom once when the board boots up.
}
EEPROM_writeAnything returns the number of bytes that were transferred. Now, for an int we know that only 2 bytes will be used so I could have written the following:
EEPROM_writeAnything(0, b);
EEPROM_writeAnything(2, b);
EEPROM_writeAnything(4, c);
I'd rather not hardcode the memory addresses being used, (and neither should you) and perhaps in the future you will decide to write different data types which will use a different number of bytes. By having a variable known as eeprom_address that updates each time something is written to eeprom, we are not hard coding anything, hence leading to an efficient implementation.
P.S - Halley please correct if I've posted anything incorrect. This is the first time I'm using your function. Good job on the template though.