@@ -13,78 +13,127 @@ void setup() {
1313 // put your setup code here, to run once:
1414 Serial.begin (115200 );
1515 Serial.println (" \n Testing EEPROM Library\n " );
16- if (!EEPROM.begin (EEPROM. length () )) {
16+ if (!EEPROM.begin (1000 )) {
1717 Serial.println (" Failed to initialise EEPROM" );
1818 Serial.println (" Restarting..." );
1919 delay (1000 );
2020 ESP.restart ();
2121 }
2222
23- int address = 0 ; // Same address is used through the example
23+ int address = 0 ;
2424
2525 EEPROM.writeByte (address, -128 ); // -2^7
26- Serial. println (EEPROM. readByte ( address) );
26+ address += sizeof (byte );
2727
2828 EEPROM.writeChar (address, ' A' ); // Same as writyByte and readByte
29- Serial. println (char (EEPROM. readChar (address)) );
29+ address += sizeof (char );
3030
3131 EEPROM.writeUChar (address, 255 ); // 2^8 - 1
32- Serial. println (EEPROM. readUChar ( address) );
32+ address += sizeof ( unsigned char );
3333
3434 EEPROM.writeShort (address, -32768 ); // -2^15
35- Serial. println (EEPROM. readShort ( address) );
35+ address += sizeof ( short );
3636
3737 EEPROM.writeUShort (address, 65535 ); // 2^16 - 1
38- Serial. println (EEPROM. readUShort ( address) );
38+ address += sizeof ( unsigned short );
3939
4040 EEPROM.writeInt (address, -2147483648 ); // -2^31
41- Serial. println (EEPROM. readInt ( address) );
41+ address += sizeof ( int );
4242
4343 EEPROM.writeUInt (address, 4294967295 ); // 2^32 - 1
44- Serial. println (EEPROM. readUInt ( address) );
44+ address += sizeof ( unsigned int );
4545
4646 EEPROM.writeLong (address, -2147483648 ); // Same as writeInt and readInt
47- Serial. println (EEPROM. readLong ( address) );
47+ address += sizeof ( long );
4848
4949 EEPROM.writeULong (address, 4294967295 ); // Same as writeUInt and readUInt
50- Serial. println (EEPROM. readULong ( address) );
50+ address += sizeof ( unsigned long );
5151
5252 int64_t value = -9223372036854775808 ; // -2^63
5353 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 ;
55109 value = EEPROM.readLong64 (value);
56110 Serial.printf (" 0x%08X" , (uint32_t )(value >> 32 )); // Print High 4 bytes in HEX
57111 Serial.printf (" %08X\n " , (uint32_t )value); // Print Low 4 bytes in HEX
112+ address += sizeof (int64_t );
58113
59- uint64_t Value = 18446744073709551615 ; // 2^64 - 1
60- EEPROM.writeULong64 (address, Value);
61114 Value = 0 ; // Clear Value
62115 Value = EEPROM.readULong64 (Value);
63116 Serial.printf (" 0x%08X" , (uint32_t )(Value >> 32 )); // Print High 4 bytes in HEX
64117 Serial.printf (" %08X\n " , (uint32_t )Value); // Print Low 4 bytes in HEX
118+ address += sizeof (uint64_t );
65119
66- EEPROM.writeFloat (address, 1234.1234 );
67120 Serial.println (EEPROM.readFloat (address), 4 );
121+ address += sizeof (float );
68122
69- EEPROM.writeDouble (address, 123456789.123456789 );
70123 Serial.println (EEPROM.readDouble (address), 8 );
124+ address += sizeof (double );
71125
72- EEPROM.writeBool (address, true );
73126 Serial.println (EEPROM.readBool (address));
127+ address += sizeof (bool );
74128
75- String sentence = " I love ESP32." ;
76- EEPROM.writeString (address, sentence);
77129 Serial.println (EEPROM.readString (address));
130+ address += sentence.length () + 1 ;
78131
79- char gratitude[] = " Thank You Espressif!" ;
80- EEPROM.writeString (address, gratitude);
81132 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 ;
85134}
86135
87136void loop () {
88137 // put your main code here, to run repeatedly:
89138
90- }
139+ }
0 commit comments