File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed
hardware/arduino/avr/libraries/EEPROM/examples Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change 11
11
#include < EEPROM.h>
12
12
13
13
void setup () {
14
+
14
15
// initialize the LED pin as an output.
15
16
pinMode (13 , OUTPUT);
16
-
17
+
17
18
/* **
18
19
Iterate through each byte of the EEPROM storage.
19
20
@@ -27,7 +28,14 @@ void setup() {
27
28
***/
28
29
29
30
for (int i = 0 ; i < EEPROM.length () ; i++) {
30
- EEPROM.write (i, 0 );
31
+
32
+ /*
33
+ Use the update method to prevent un-necessary wear on already cleared cells.
34
+ The update method checks to see if the current cell is different before writing.
35
+ You could easily replace this with EEPROM.write(i, 0); or even EEPROM.put(i, 0);
36
+ */
37
+
38
+ EEPROM.update (i, 0 );
31
39
}
32
40
33
41
// turn the LED on when we're done
Original file line number Diff line number Diff line change 17
17
18
18
#include < EEPROM.h>
19
19
20
+ // EEPROM address to start reading from. This does not need to be global, but in this example, it is shared between two different functions.
21
+ int eeAddress = 0 ;
22
+
20
23
void setup () {
21
24
22
25
float f = 0 .00f ; // Variable to store data read from EEPROM.
23
- int eeAddress = 0 ; // EEPROM address to start reading from
24
26
25
27
Serial.begin (9600 );
26
28
while (!Serial) {
@@ -52,7 +54,7 @@ struct MyObject {
52
54
};
53
55
54
56
void secondTest () {
55
- int eeAddress = sizeof (float ); // Move address to the next byte after float 'f'.
57
+ eeAddress + = sizeof (float ); // Move address to the next byte after float 'f'.
56
58
57
59
MyObject customVar; // Variable to store custom object read from EEPROM.
58
60
EEPROM.get (eeAddress, customVar);
You can’t perform that action at this time.
0 commit comments