EEPROM Class

This library enables use of the data flash memory mounted on the microcontroller (MCU) as EEPROM which enables retention of data even after power off. With 32KB of EEPROM, the memory can be reprogrammed approximately 50,000 times.

To use this EEPROM library, specify #include <EEPROM.h>.

read

Description
Reads 1 byte from the EEPROM address.
Syntax
unsigned char EEPROM.read(unsigned long address)
Parameters
address: (0 ~ 32767)
Returns
Data read from the EEPROM.

write

Description
Writes (stores) 1 byte of data in the EEPROM
Syntax
int EEPROM.write(unsigned long address, unsigned char data)
Parameters
address: (0 ~ 32767)
data: Data to be written
Returns
None

Sample Program

This is a sample for EEPROM.write and EEPROM.read. The position of the LED flash changes by turning GR-SAKURA on or off.


#include <Arduino.h>
#include <EEPROM.h>
void setup()
{
    pinMode(PIN_LED0, OUTPUT);
    pinMode(PIN_LED1, OUTPUT);
    pinMode(PIN_LED2, OUTPUT);
    pinMode(PIN_LED3, OUTPUT);
     
    uint8_t mode = EEPROM.read(0);
    if(mode == 0){
        digitalWrite(PIN_LED0, HIGH);
        EEPROM.write(0, 1);
    } else if (mode == 1){
        digitalWrite(PIN_LED1, HIGH);
        EEPROM.write(0, 2);
    } else if (mode == 2){
        digitalWrite(PIN_LED2, HIGH);
        EEPROM.write(0, 3);
    } else {
        digitalWrite(PIN_LED3, HIGH);
        EEPROM.write(0, 0);
    }
}
  
void loop()
{
}