From dd1ec9920b8fd6b445cdcc943f53333990b34428 Mon Sep 17 00:00:00 2001 From: Chris--A Date: Tue, 17 Mar 2015 17:17:08 +1000 Subject: Added additional examples to EEPROM lib --- .../examples/eeprom_iteration/eeprom_iteration.ino | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino (limited to 'libraries/EEPROM/examples/eeprom_iteration') diff --git a/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino b/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino new file mode 100644 index 0000000..34071fc --- /dev/null +++ b/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino @@ -0,0 +1,73 @@ +/*** + eeprom_iteration example. + + A set of example snippets highlighting the + simplest methods for traversing the EEPROM. + + Running this sketch is not necessary, this is + simply highlighting certain programming methods. + + Written by Christopher Andrews 2015 + Released under MIT licence. +***/ + +#include + +void setup() { + + /*** + Iterate the EEPROM using a for loop. + ***/ + + for( int index = 0 ; index < EEPROM.length() ; index++ ){ + + //Add one to each cell in the EEPROM + EEPROM[ index ] += 1; + } + + /*** + Iterate the EEPROM using a while loop. + ***/ + + int index = 0; + + while( index < EEPROM.length() ){ + + //Add one to each cell in the EEPROM + EEPROM[ index ] += 1; + index++; + } + + /*** + Iterate the EEPROM using a do-while loop. + ***/ + + int idx = 0; + + do{ + + //Add one to each cell in the EEPROM + EEPROM[ index ] += 1; + index++; + }while( index < EEPROM.length() ); + + /*** + Iterate the EEPROM using a C++11 ranged for loop. + + This version of the loop is best explained in the example 'eeprom_pointer' + as this kind of iteration uses pointers rather than an index/integer. + + !! Note: C++11 is not yet enabled by default in any IDE version. + Unless you manually enable it, this sketch will not compile. + You can comment the loop below to verify the non C++11 content. + ***/ + + for( auto cell : EEPROM ){ + + //Add one to each cell in the EEPROM + cell += 1; + } + +} //End of setup function. + +void loop(){} \ No newline at end of file -- cgit v1.2.3-18-g5258 From fd4323f360885725c736c90745ee57dbca20e8a0 Mon Sep 17 00:00:00 2001 From: Chris--A Date: Thu, 19 Mar 2015 17:13:32 +1000 Subject: Small tweaks to EEPROM lib and examples. --- libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'libraries/EEPROM/examples/eeprom_iteration') diff --git a/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino b/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino index 34071fc..a2d825c 100644 --- a/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino +++ b/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino @@ -42,14 +42,14 @@ void setup() { Iterate the EEPROM using a do-while loop. ***/ - int idx = 0; + int idx = 0; //Used 'idx' to avoid name conflict with 'index' above. do{ //Add one to each cell in the EEPROM - EEPROM[ index ] += 1; - index++; - }while( index < EEPROM.length() ); + EEPROM[ idx ] += 1; + idx++; + }while( idx < EEPROM.length() ); /*** Iterate the EEPROM using a C++11 ranged for loop. -- cgit v1.2.3-18-g5258 From 5da9792cd61b5ba9eed9fb80874edb52081d6232 Mon Sep 17 00:00:00 2001 From: Chris--A Date: Tue, 24 Mar 2015 13:58:01 +1000 Subject: Fixed EEPROM examples and added readme --- .../examples/eeprom_iteration/eeprom_iteration.ino | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'libraries/EEPROM/examples/eeprom_iteration') diff --git a/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino b/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino index a2d825c..650c90a 100644 --- a/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino +++ b/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino @@ -51,22 +51,6 @@ void setup() { idx++; }while( idx < EEPROM.length() ); - /*** - Iterate the EEPROM using a C++11 ranged for loop. - - This version of the loop is best explained in the example 'eeprom_pointer' - as this kind of iteration uses pointers rather than an index/integer. - - !! Note: C++11 is not yet enabled by default in any IDE version. - Unless you manually enable it, this sketch will not compile. - You can comment the loop below to verify the non C++11 content. - ***/ - - for( auto cell : EEPROM ){ - - //Add one to each cell in the EEPROM - cell += 1; - } } //End of setup function. -- cgit v1.2.3-18-g5258