From b5a130afb51c971fd7ceca8834b6055f1eada253 Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Mon, 6 Jul 2015 15:18:33 +0200 Subject: Examples: mass code format. See example_formatter.conf --- .../EEPROM/examples/eeprom_read/eeprom_read.ino | 23 +++++++++++----------- 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'libraries/EEPROM/examples/eeprom_read/eeprom_read.ino') diff --git a/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino b/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino index 68c4ffc..25bc5d9 100644 --- a/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino +++ b/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino @@ -12,8 +12,7 @@ int address = 0; byte value; -void setup() -{ +void setup() { // initialize serial and wait for port to open: Serial.begin(9600); while (!Serial) { @@ -21,8 +20,7 @@ void setup() } } -void loop() -{ +void loop() { // read a byte from the current address of the EEPROM value = EEPROM.read(address); @@ -32,24 +30,25 @@ void loop() Serial.println(); /*** - Advance to the next address, when at the end restart at the beginning. - + Advance to the next address, when at the end restart at the beginning. + Larger AVR processors have larger EEPROM sizes, E.g: - Arduno Duemilanove: 512b EEPROM storage. - Arduino Uno: 1kb EEPROM storage. - Arduino Mega: 4kb EEPROM storage. - + Rather than hard-coding the length, you should use the pre-provided length function. - This will make your code portable to all AVR processors. + This will make your code portable to all AVR processors. ***/ address = address + 1; - if(address == EEPROM.length()) + if (address == EEPROM.length()) { address = 0; - + } + /*** - As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an + As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an EEPROM address is also doable by a bitwise and of the length - 1. - + ++address &= EEPROM.length() - 1; ***/ -- cgit v1.2.3-18-g5258