EEPROM Class

This library enables use of the Data Flash memory mounted on the MCU as EEPROM that enables the retention of data even after power off. With 32KB of EEPROM, the memory can be reprogrammed approximately 50,000 times. To use as the EEPROM, 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

Sample program for EEPROM.write and EEPROM.read. The position of the LED flash changes by turning GR-KAEDE 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()
{
}