@@ -13,78 +13,127 @@ void setup() {
13
13
// put your setup code here, to run once:
14
14
Serial.begin (115200 );
15
15
Serial.println (" \n Testing EEPROM Library\n " );
16
- if (!EEPROM.begin (EEPROM. length () )) {
16
+ if (!EEPROM.begin (1000 )) {
17
17
Serial.println (" Failed to initialise EEPROM" );
18
18
Serial.println (" Restarting..." );
19
19
delay (1000 );
20
20
ESP.restart ();
21
21
}
22
22
23
- int address = 0 ; // Same address is used through the example
23
+ int address = 0 ;
24
24
25
25
EEPROM.writeByte (address, -128 ); // -2^7
26
- Serial. println (EEPROM. readByte ( address) );
26
+ address += sizeof (byte );
27
27
28
28
EEPROM.writeChar (address, ' A' ); // Same as writyByte and readByte
29
- Serial. println (char (EEPROM. readChar (address)) );
29
+ address += sizeof (char );
30
30
31
31
EEPROM.writeUChar (address, 255 ); // 2^8 - 1
32
- Serial. println (EEPROM. readUChar ( address) );
32
+ address += sizeof ( unsigned char );
33
33
34
34
EEPROM.writeShort (address, -32768 ); // -2^15
35
- Serial. println (EEPROM. readShort ( address) );
35
+ address += sizeof ( short );
36
36
37
37
EEPROM.writeUShort (address, 65535 ); // 2^16 - 1
38
- Serial. println (EEPROM. readUShort ( address) );
38
+ address += sizeof ( unsigned short );
39
39
40
40
EEPROM.writeInt (address, -2147483648 ); // -2^31
41
- Serial. println (EEPROM. readInt ( address) );
41
+ address += sizeof ( int );
42
42
43
43
EEPROM.writeUInt (address, 4294967295 ); // 2^32 - 1
44
- Serial. println (EEPROM. readUInt ( address) );
44
+ address += sizeof ( unsigned int );
45
45
46
46
EEPROM.writeLong (address, -2147483648 ); // Same as writeInt and readInt
47
- Serial. println (EEPROM. readLong ( address) );
47
+ address += sizeof ( long );
48
48
49
49
EEPROM.writeULong (address, 4294967295 ); // Same as writeUInt and readUInt
50
- Serial. println (EEPROM. readULong ( address) );
50
+ address += sizeof ( unsigned long );
51
51
52
52
int64_t value = -9223372036854775808 ; // -2^63
53
53
EEPROM.writeLong64 (address, value);
54
- value = 0 ; // Clear value
54
+ address += sizeof (int64_t );
55
+
56
+ uint64_t Value = 18446744073709551615 ; // 2^64 - 1
57
+ EEPROM.writeULong64 (address, Value);
58
+ address += sizeof (uint64_t );
59
+
60
+ EEPROM.writeFloat (address, 1234.1234 );
61
+ address += sizeof (float );
62
+
63
+ EEPROM.writeDouble (address, 123456789.123456789 );
64
+ address += sizeof (double );
65
+
66
+ EEPROM.writeBool (address, true );
67
+ address += sizeof (bool );
68
+
69
+ String sentence = " I love ESP32." ;
70
+ EEPROM.writeString (address, sentence);
71
+ address += sentence.length () + 1 ;
72
+
73
+ char gratitude[21 ] = " Thank You Espressif!" ;
74
+ EEPROM.writeString (address, gratitude);
75
+ address += 21 ;
76
+
77
+ // See also the general purpose writeBytes() and readBytes() for BLOB in EEPROM library
78
+ EEPROM.commit ();
79
+ address = 0 ;
80
+
81
+ Serial.println (EEPROM.readByte (address));
82
+ address += sizeof (byte);
83
+
84
+ Serial.println ((char )EEPROM.readChar (address));
85
+ address += sizeof (char );
86
+
87
+ Serial.println (EEPROM.readUChar (address));
88
+ address += sizeof (unsigned char );
89
+
90
+ Serial.println (EEPROM.readShort (address));
91
+ address += sizeof (short );
92
+
93
+ Serial.println (EEPROM.readUShort (address));
94
+ address += sizeof (unsigned short );
95
+
96
+ Serial.println (EEPROM.readInt (address));
97
+ address += sizeof (int );
98
+
99
+ Serial.println (EEPROM.readUInt (address));
100
+ address += sizeof (unsigned int );
101
+
102
+ Serial.println (EEPROM.readLong (address));
103
+ address += sizeof (long );
104
+
105
+ Serial.println (EEPROM.readULong (address));
106
+ address += sizeof (unsigned long );
107
+
108
+ value = 0 ;
55
109
value = EEPROM.readLong64 (value);
56
110
Serial.printf (" 0x%08X" , (uint32_t )(value >> 32 )); // Print High 4 bytes in HEX
57
111
Serial.printf (" %08X\n " , (uint32_t )value); // Print Low 4 bytes in HEX
112
+ address += sizeof (int64_t );
58
113
59
- uint64_t Value = 18446744073709551615 ; // 2^64 - 1
60
- EEPROM.writeULong64 (address, Value);
61
114
Value = 0 ; // Clear Value
62
115
Value = EEPROM.readULong64 (Value);
63
116
Serial.printf (" 0x%08X" , (uint32_t )(Value >> 32 )); // Print High 4 bytes in HEX
64
117
Serial.printf (" %08X\n " , (uint32_t )Value); // Print Low 4 bytes in HEX
118
+ address += sizeof (uint64_t );
65
119
66
- EEPROM.writeFloat (address, 1234.1234 );
67
120
Serial.println (EEPROM.readFloat (address), 4 );
121
+ address += sizeof (float );
68
122
69
- EEPROM.writeDouble (address, 123456789.123456789 );
70
123
Serial.println (EEPROM.readDouble (address), 8 );
124
+ address += sizeof (double );
71
125
72
- EEPROM.writeBool (address, true );
73
126
Serial.println (EEPROM.readBool (address));
127
+ address += sizeof (bool );
74
128
75
- String sentence = " I love ESP32." ;
76
- EEPROM.writeString (address, sentence);
77
129
Serial.println (EEPROM.readString (address));
130
+ address += sentence.length () + 1 ;
78
131
79
- char gratitude[] = " Thank You Espressif!" ;
80
- EEPROM.writeString (address, gratitude);
81
132
Serial.println (EEPROM.readString (address));
82
-
83
- // See also the general purpose writeBytes() and readBytes() for BLOB in EEPROM library
84
- // To avoid data overwrite, next address should be chosen/offset by using "address =+ sizeof(previousData)"
133
+ address += 21 ;
85
134
}
86
135
87
136
void loop () {
88
137
// put your main code here, to run repeatedly:
89
138
90
- }
139
+ }
0 commit comments