Not sure if things have changed so significantly since the question was asked originally but modernI'll answer using current arduino IDEthe Atmel AVR libraries.
Don't assign the EEPROM value to a variable as then you are wasting precious SRAM again. EEPROM has unlimited read cycles.
I can't find any current references to EEPROM.read()EEPROM.read() as a Macro or function in the Arduino IDE. Instead there is the AVR EEPROM library which uses eeprom_read_byte() as shown below.
#include <avr/eeprom.h>
// the setup routine runs once when you press reset:
void setup() {
/* The "131" value is used to prevent damaging excess EEPROM writes on every restart.
If you want to try setting a different GPIO pin for LED blink change the test value in
both the read and following write to EEPROM address 511 */
if (eeprom_read_byte((uint8_t*)511) != 131) {
eeprom_write_byte((uint8_t*)511,131);
// Store the GPIO pin number in EEPROM address 1
eeprom_write_byte((uint8_t*)1,1);
};
// initialize the digital pin as an output.
pinMode(eeprom_read_byte((uint8_t*)1), OUTPUT); // LED pin value stored in EEPROM address 1
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(eeprom_read_byte((uint8_t*)1), HIGH);
delay(1000); // wait for a second
digitalWrite(eeprom_read_byte((uint8_t*)1), LOW);
delay(1000); // wait for a second
}
#include <avr/eeprom.h>
// the setup routine runs once when you press reset:
void setup() {
/* The "131" value is used to prevent damaging excess EEPROM writes on every restart.
If you want to try setting a different GPIO pin for LED blink change the test value in
both the read and following write to EEPROM address 511 */
if (eeprom_read_byte((uint8_t*)511) != 131) {
eeprom_write_byte((uint8_t*)511,131);
// Store the GPIO pin number in EEPROM address 1
eeprom_write_byte((uint8_t*)1,1);
};
// initialize the digital pin as an output.
pinMode(eeprom_read_byte((uint8_t*)1), OUTPUT); // LED pin value stored in EEPROM address 1
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(eeprom_read_byte((uint8_t*)1), HIGH);
delay(1000); // wait for a second
digitalWrite(eeprom_read_byte((uint8_t*)1), LOW);
delay(1000); // wait for a second
}