將變數儲存在 EEPROM 中,然後將其檢索並列印到螢幕
首先,在草圖的開頭新增對 <EEPROM.h>
的引用:
#include <EEPROM.h>
然後你的其他程式碼:
// Stores value in a particular address in EEPROM. There are almost 512 addresses present.
// Store value 24 to Address 0 in EEPROM
int addr = 0;
int val = 24;
EEPROM.write(addr, val); // Writes 24 to address 0
// ---------
// Retrieves value from a particular address in EEPROM
// Retrieve value from address 0 in EEPROM
int retrievedVal = EEPROM.read(0); // Retrieves value stored in 0 address in
// EEPROM
// *[NOTE: put Serial.begin(9600); at void setup()]*
Serial.println(retrievedVal); // Prints value stored in EEPROM Address 0 to
// Serial (screen)