23
23
24
24
void setup ()
25
25
{
26
- Serial.begin (9600 );
26
+ Serial.begin (115200 );
27
27
Serial.println (" EEPROM Examples" );
28
28
29
29
randomSeed (analogRead (A0));
30
30
31
31
long startTime;
32
32
long endTime;
33
- uint16_t randomLocation;
33
+ int randomLocation;
34
34
35
35
// Test erase time
36
36
startTime = millis ();
@@ -53,6 +53,12 @@ void setup()
53
53
54
54
Serial.printf (" Write byte time: %dms\n " , endTime - startTime);
55
55
56
+ startTime = millis ();
57
+ EEPROM.write (randomLocation, myValue1); // (location, data)
58
+ endTime = millis ();
59
+
60
+ Serial.printf (" Write identical byte to same location (should be ~1): %dms\n " , endTime - startTime);
61
+
56
62
byte response1 = EEPROM.read (randomLocation);
57
63
byte response2 = EEPROM.read (randomLocation + 1 );
58
64
Serial.printf (" Location %d should be %d: %d\n\r " , randomLocation, myValue1, response1);
@@ -106,8 +112,8 @@ void setup()
106
112
uint32_t myValue8 = 241544 ;
107
113
randomLocation = random (0 , AP3_FLASH_EEPROM_SIZE);
108
114
109
- EEPROM.update (randomLocation, myValue7);
110
- EEPROM.update (randomLocation + 4 , myValue8);
115
+ EEPROM.put (randomLocation, myValue7);
116
+ EEPROM.put (randomLocation + 4 , myValue8);
111
117
112
118
int32_t response7;
113
119
uint32_t response8;
@@ -124,8 +130,8 @@ void setup()
124
130
float myValue10 = 5.22 ;
125
131
randomLocation = random (0 , AP3_FLASH_EEPROM_SIZE);
126
132
127
- EEPROM.update (randomLocation, myValue9);
128
- EEPROM.update (randomLocation + 4 , myValue10);
133
+ EEPROM.put (randomLocation, myValue9);
134
+ EEPROM.put (randomLocation + 4 , myValue10);
129
135
130
136
float response9;
131
137
float response10;
@@ -143,20 +149,50 @@ void setup()
143
149
Serial.printf (" Size of double: %d\n " , sizeof (double ));
144
150
double myValue11 = -290.3485723409857 ;
145
151
double myValue12 = 384.95734987 ;
152
+ double myValue13 = 917.14159 ;
153
+ double myValue14 = 254.8877 ;
146
154
randomLocation = random (0 , AP3_FLASH_EEPROM_SIZE);
147
155
148
- EEPROM.update (randomLocation, myValue11);
149
- EEPROM.update (randomLocation + 8 , myValue12);
156
+ startTime = millis ();
157
+ EEPROM.put (randomLocation, myValue11);
158
+ endTime = millis ();
159
+ Serial.printf (" Time to record 64-bits: %dms\n " , endTime - startTime);
160
+
161
+ EEPROM.put (randomLocation + 8 , myValue12);
162
+ EEPROM.put (EEPROM.length () - sizeof (myValue13), myValue13); // Test end of EEPROM space
150
163
151
164
double response11;
152
165
double response12;
166
+ double response13;
153
167
EEPROM.get (randomLocation, response11);
154
168
EEPROM.get (randomLocation + 8 , response12);
169
+ EEPROM.get (EEPROM.length () - sizeof (myValue13), response13);
155
170
Serial.printf (" Location %d should be %lf: %lf\n " , randomLocation, myValue11, response11);
156
171
Serial.printf (" Location %d should be %lf: %lf\n " , randomLocation + 8 , myValue12, response12);
172
+ Serial.printf (" Edge of EEPROM %d should be %lf: %lf\n " , EEPROM.length () - sizeof (myValue13), myValue13, response13);
173
+
174
+ double response14;
175
+ EEPROM.put (EEPROM.length () - sizeof (myValue14), myValue14); // Test the re-write of a spot
176
+ EEPROM.get (EEPROM.length () - sizeof (myValue14), response14);
177
+ Serial.printf (" Rewrite of %d should be %lf: %lf\n " , EEPROM.length () - sizeof (myValue14), myValue14, response14);
157
178
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
158
179
159
- Serial.println ();
180
+ Serial.println (" " );
181
+ Serial.println (" String test" );
182
+
183
+ // String write test
184
+ // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
185
+ char myString[19 ] = " How are you today?" ;
186
+ randomLocation = random (0 , AP3_FLASH_EEPROM_SIZE);
187
+ EEPROM.put (randomLocation, myString);
188
+
189
+ char readMy[19 ];
190
+ EEPROM.get (randomLocation, readMy);
191
+ Serial.printf (" Location %d string should read 'How are you today?': " , randomLocation);
192
+ Serial.println (readMy);
193
+ // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
194
+
195
+ Serial.println (" " );
160
196
Serial.print (" Flash Contents:" );
161
197
for (uint16_t x = 0 ; x < 8 * 4 ; x += 4 )
162
198
{
0 commit comments