EEPROM in Arduino
1024 bytes that survive power loss.
// EEPROM survives power loss: 1024 bytes of remember-me.
#include <EEPROM.h>
const int THRESHOLD_ADDR = 0;
void setup() {
Serial.begin(9600);
int saved = EEPROM.read(THRESHOLD_ADDR);
Serial.print("Saved threshold: ");
Serial.println(saved);
// update only writes when the value changed -- cells wear out.
EEPROM.update(THRESHOLD_ADDR, 180);
}
void loop() {
}
How it works
#include <EEPROM.h>brings in the persistent store.EEPROM.readrecovers the byte saved last session.updatewrites only on change — cells wear out.
Keywords and builtins used here
EEPROMSerialbeginconstintloopprintprintlnreadsetupvoid
The run, in numbers
- Lines
- 16
- Characters to type
- 362
- Tokens
- 65
- Three-star pace
- 65 tpm
At the three-star pace of 65 tokens a minute, this run takes about 60 seconds.
Step 3 of 3 in Data, step 21 of 27 in Language basics.