Debian Codegraph @

libraries/EEPROM/examples/eeprom_read/eeprom_read.ino

raw
1 /*
2 * EEPROM Read
3 *
4 * Reads the value of each byte of the EEPROM and prints it
5 * to the computer.
6 * This example code is in the public domain.
7 */
8
9 #include <EEPROM.h>
10
11 // start reading from the first byte (address 0) of the EEPROM
12 int address = 0;
13 byte value;
14
15 void setup() {
16 // initialize serial and wait for port to open:
17 Serial.begin(9600);
18 while (!Serial) {
19 ; // wait for serial port to connect. Needed for native USB port only
20 }
21 }
22
23 void loop() {
24 // read a byte from the current address of the EEPROM
25 value = EEPROM.read(address);
26
27 Serial.print(address);
28 Serial.print("\t");
29 Serial.print(value, DEC);
30 Serial.println();
31
32 /***
33 Advance to the next address, when at the end restart at the beginning.
34
35 Larger AVR processors have larger EEPROM sizes, E.g:
36 - Arduino Duemilanove: 512 B EEPROM storage.
37 - Arduino Uno: 1 kB EEPROM storage.
38 - Arduino Mega: 4 kB EEPROM storage.
39
40 Rather than hard-coding the length, you should use the pre-provided length function.
41 This will make your code portable to all AVR processors.
42 ***/
43 address = address + 1;
44 if (address == EEPROM.length()) {
45 address = 0;
46 }
47
48 /***
49 As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an
50 EEPROM address is also doable by a bitwise and of the length - 1.
51
52 ++address &= EEPROM.length() - 1;
53 ***/
54
55 delay(500);
56 }