#include <EEPROM.h>
void setup() {
int address = 0; //Location we want the data to be put.
for (int value = 10; value >= 5; --value)
{
// Write the int at address
EEPROM.put(eeAddress, value)
// Move the address, so the next value will be written after the first.
address += sizeof(int);
}
}
void loop() {
}
1 回答
Arduino Uno具有1KB的非易失性EEPROM存储器,您可以将其用于此目的 . 整数是2个字节,因此您应该能够以这种方式存储超过500个int .
此示例草图应将10到5的几个整数写入EEPROM存储器:
此示例是EEPROM.put documentation中的一个精简版本 . 其他示例可以在documentation of the various EEPROM functions中找到 . 关于这个主题的另一个很好的教程可以在tronixstuff上找到 .
顺便说一句,如果你需要更多内存,你也可以使用EEPROM内存库 . 这些是小型IC . 它们的内存容量很低,价格非常低,通常从1KB到256KB . 在现代计算方面并不多,但与默认情况下的1KB相比,这是一个巨大的扩展 .