source: arduino-1-6-7/trunk/fuentes/arduino-ide-amd64/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino @ 46

Last change on this file since 46 was 46, checked in by jrpelegrina, 4 years ago

First release to Xenial

File size: 1.4 KB
Line 
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
12int address = 0;
13byte value;
14
15void 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
23void 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    - Arduno Duemilanove: 512b EEPROM storage.
37    - Arduino Uno:        1kb EEPROM storage.
38    - Arduino Mega:       4kb 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}
Note: See TracBrowser for help on using the repository browser.