I would recommend reading a button or something to control when the writes happen so you don't just sit there & pound the living daylights out of that 1 location by accident, they do have limited durability. As pointed out, you start writing to address 0 whenever the sketch starts - maybe change the sketch to read first, with "a = EEPROM.read(address);", then continue incrementing "a" from there.
Virgin EEPROM addresses will have 0xFF (255 decimal) when read back.
Keep in mind that EEPROM.write has built in 3.3mS time to complete, which you provide for with 500mS delay. If you capture the time written as part of a loop of doing other stuff, and check that 3.3ms have gone by before starting the next write, you can be doing other stuff while waiting (this is the heart of Blink Without Delay).
that was all I needed to do, the problem is solved thank you very much, and yes I will be using buttons to activate the code in other projects
As just a little side note, thank you to the other two who also posted help and in refference to the second reply, pressding the reset button does not erase the EEPROM variables, they stay exactly the same.
for the benifit of others, here is the working code, I hope it helps in the future:
#include <EEPROM.h>
int address;
int value;
int a=EEPROM.read(address);
void setup(){
Serial.begin(9600);
}
void loop(){
//Lets first write a value to the eeprom
if ((a==255)){
a=0;
}
EEPROM.write(address,a);
a++;
delay(500);
if(a>100){a=0;}
//Lets read the value back and print it to the serial
value = EEPROM.read(address);
//Output the data to serial
Serial.print(value,DEC); // will print 123
Serial.print("\n");
//Serial.print(value,BIN); // will print 1111011 which is 123 in binary
}
Peace out
Chris.