Arduino EEPROM Library#

抽象#

  • EEPROM.length 保存了 EEPROM 的空间大小,单位为字节。 UNO 为 1K 字节

  • 一片连续的字节存储空间 Array,可按字节地址随机访问: read(addr), write(addr, val), EEPROM[index]

  • put(addr, val), get() 为连续存与取,val 可以是单节 data type, 如 int, float,也可以是 struct, array

  • update(addr, val) 为单个地址的值的更新。和 write() 相比可以节省时间和增长EEPROM寿命。

Usage#

for (int i = 0 ; i < EEPROM.length() ; i++) {
  EEPROM.write(i, 0);
}

写浮点数

float f = 123.456f;  //Variable to store in EEPROM.
int eeAddress = 0;   //Location we want the data to be put.
//One simple call, with the address first and the object second.
EEPROM.put(eeAddress, f);

Guide with Examples#

https://docs.arduino.cc/learn/programming/eeprom-guide#eeprom-write

More#

https://docs.arduino.cc/learn/programming/memory-guide