Skip to content

Commit 9c74e43

Browse files
author
James Foster
committed
Add documentation of EEPROM (fix Arduino-CI#190).
1 parent 9b5cd4c commit 9c74e43

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

Diff for: REFERENCE.md

+37
Original file line numberDiff line numberDiff line change
@@ -581,3 +581,40 @@ unittest(spi) {
581581
assertEqual("LMNOe", String(inBuf));
582582
}
583583
```
584+
585+
### EEPROM
586+
587+
`EEPROM` is a global with a simple API to read and write bytes to persistent memory (like a tiny hard disk) given an `int` location. Since the Arduino core already provides this as a global, and the core API is sufficient for basic testing (read/write), there is no direct tie to the `GODMODE` API. (If you need more, such as a log of intermediate values, enter a feature request.)
588+
589+
```C++
590+
unittest(eeprom)
591+
{
592+
uint8_t a;
593+
// size
594+
assertEqual(EEPROM_SIZE, EEPROM.length());
595+
// initial values
596+
a = EEPROM.read(0);
597+
assertEqual(255, a);
598+
// write and read
599+
EEPROM.write(0, 24);
600+
a = EEPROM.read(0);
601+
assertEqual(24, a);
602+
// update
603+
EEPROM.write(1, 14);
604+
EEPROM.update(1, 22);
605+
a = EEPROM.read(1);
606+
assertEqual(22, a);
607+
// put and get
608+
const float f1 = 0.025f;
609+
float f2 = 0.0f;
610+
EEPROM.put(5, f1);
611+
assertEqual(0.0f, f2);
612+
EEPROM.get(5, f2);
613+
assertEqual(0.025f, f2);
614+
// array access
615+
int val = 10;
616+
EEPROM[2] = val;
617+
a = EEPROM[2];
618+
assertEqual(10, a);
619+
}
620+
```

0 commit comments

Comments
 (0)