aboutsummaryrefslogtreecommitdiff
path: root/libraries/EEPROM/examples
diff options
context:
space:
mode:
authorChris--A <chris@genx.biz>2015-03-24 13:58:01 +1000
committerChris--A <chris@genx.biz>2015-03-24 13:58:01 +1000
commit5da9792cd61b5ba9eed9fb80874edb52081d6232 (patch)
tree13ea73606522e092346c2b9c84020870e8efae72 /libraries/EEPROM/examples
parent26577474efcb8874dad687467a8ba2f01678ff4c (diff)
Fixed EEPROM examples and added readme
Diffstat (limited to 'libraries/EEPROM/examples')
-rw-r--r--libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino2
-rw-r--r--libraries/EEPROM/examples/eeprom_get/eeprom_get.ino2
-rw-r--r--libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino16
-rw-r--r--libraries/EEPROM/examples/eeprom_pointer/eeprom_pointer.ino74
-rw-r--r--libraries/EEPROM/examples/eeprom_put/eeprom_put.ino12
-rw-r--r--libraries/EEPROM/examples/eeprom_read/eeprom_read.ino8
-rw-r--r--libraries/EEPROM/examples/eeprom_reference/eeprom_reference.ino93
-rw-r--r--libraries/EEPROM/examples/eeprom_update/eeprom_update.ino18
8 files changed, 21 insertions, 204 deletions
diff --git a/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino b/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino
index 40b08bd..a4baacc 100644
--- a/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino
+++ b/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino
@@ -38,7 +38,7 @@ unsigned long eeprom_crc( void ){
unsigned long crc = ~0L;
- for( int index = 0 ; index < 32 ; ++index ){
+ for( int index = 0 ; index < EEPROM.length() ; ++index ){
crc = crc_table[( crc ^ EEPROM[index] ) & 0x0f] ^ (crc >> 4);
crc = crc_table[( crc ^ ( EEPROM[index] >> 4 )) & 0x0f] ^ (crc >> 4);
crc = ~crc;
diff --git a/libraries/EEPROM/examples/eeprom_get/eeprom_get.ino b/libraries/EEPROM/examples/eeprom_get/eeprom_get.ino
index 58475fd..dcd8678 100644
--- a/libraries/EEPROM/examples/eeprom_get/eeprom_get.ino
+++ b/libraries/EEPROM/examples/eeprom_get/eeprom_get.ino
@@ -20,7 +20,7 @@
void setup(){
float f = 0.00f; //Variable to store data read from EEPROM.
- int eeAddress = 0; //Location of the IP address inside the class.
+ int eeAddress = 0; //EEPROM address to start reading from
Serial.begin( 9600 );
Serial.print( "Read float from EEPROM: " );
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.
diff --git a/libraries/EEPROM/examples/eeprom_pointer/eeprom_pointer.ino b/libraries/EEPROM/examples/eeprom_pointer/eeprom_pointer.ino
deleted file mode 100644
index 637cdb7..0000000
--- a/libraries/EEPROM/examples/eeprom_pointer/eeprom_pointer.ino
+++ /dev/null
@@ -1,74 +0,0 @@
-/***
- eeprom_pointer example.
-
- This example shows how the built-in EEPtr
- object can be used to manipulate the EEPROM
- using standard pointer arithmetic.
-
- Running this sketch is not necessary, this is
- simply highlighting certain programming methods.
-
- Written by Christopher Andrews 2015
- Released under MIT licence.
-***/
-
-#include <EEPROM.h>
-
-void setup() {
-
- Serial.begin(9600);
-
- /***
- In this example, we will iterate forward over the EEPROM,
- starting at the 10th cell (remember indices are zero based).
- ***/
-
- EEPtr ptr = 9;
-
- //Rather than hard coding a length, we can use the provided .length() function.
-
- while( ptr < EEPROM.length() ){
-
- Serial.print( *ptr, HEX ); //Print out hex value of the EEPROM cell pointed to by 'ptr'
- Serial.print( ", " ); //Separate values with a comma.
- ptr++; //Move to next cell
- }
-
- /***
- In this example, we will iterate backwards over the EEPROM,
- starting at the last cell.
- ***/
-
- ptr = EEPROM.length() - 1;
-
- do{
-
- Serial.print( *ptr, HEX );
- Serial.print( ", " );
-
- }while( ptr-- ); //When the pointer reaches zero the loop will end as zero is considered 'false'.
-
-
- /***
- And just for clarity, the loop below is an equivalent implementation
- of the C++11 ranged for loop.
- ***/
-
- for( EEPtr ptr = EEPROM.begin() ; ptr != EEPROM.end() ; ++ptr ){
- Serial.print( *ptr, HEX );
- Serial.print( ", " );
- }
-
- /***
- The actual C++11 version:
-
- for( auto ptr : EEPROM ){
- Serial.print( *ptr, HEX );
- Serial.print( ", " );
- }
- ***/
-
-
-}
-
-void loop(){} \ No newline at end of file
diff --git a/libraries/EEPROM/examples/eeprom_put/eeprom_put.ino b/libraries/EEPROM/examples/eeprom_put/eeprom_put.ino
index 7575768..e99b4bd 100644
--- a/libraries/EEPROM/examples/eeprom_put/eeprom_put.ino
+++ b/libraries/EEPROM/examples/eeprom_put/eeprom_put.ino
@@ -16,6 +16,12 @@
#include <EEPROM.h>
+struct MyObject{
+ float field1;
+ byte field2;
+ char name[10];
+};
+
void setup(){
Serial.begin(9600);
@@ -31,12 +37,6 @@ void setup(){
/** Put is designed for use with custom structures also. **/
- struct MyObject{
- float field1;
- byte field2;
- char name[10];
- };
-
//Data to store.
MyObject customVar = {
3.14f,
diff --git a/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino b/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino
index 8567ed7..68c4ffc 100644
--- a/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino
+++ b/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino
@@ -42,15 +42,15 @@ void loop()
Rather than hard-coding the length, you should use the pre-provided length function.
This will make your code portable to all AVR processors.
***/
- addr = addr + 1;
- if(addr == EEPROM.length())
- addr = 0;
+ address = address + 1;
+ if(address == EEPROM.length())
+ address = 0;
/***
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.
- ++addr &= EEPROM.length() - 1;
+ ++address &= EEPROM.length() - 1;
***/
delay(500);
diff --git a/libraries/EEPROM/examples/eeprom_reference/eeprom_reference.ino b/libraries/EEPROM/examples/eeprom_reference/eeprom_reference.ino
deleted file mode 100644
index bcf84d6..0000000
--- a/libraries/EEPROM/examples/eeprom_reference/eeprom_reference.ino
+++ /dev/null
@@ -1,93 +0,0 @@
-/***
- eeprom_reference example.
-
- This example shows how to use the EEPROM
- reference object EERef, which allows usage
- similar to using a simple char (uint8_t in this case).
-
- Running this sketch is not necessary, this is
- simply highlighting certain programming methods.
-
- Written by Christopher Andrews 2015
- Released under MIT licence.
-***/
-
-#include <EEPROM.h>
-
-void setup() {
-
-
- /***
- To create a reference to an EEPROM cell, simply create an EERef variable.
- To let it know which cell you want to reference, you can simply assign the
- address when you create it.
- ***/
-
- EERef ref = 0;
-
- /***
- An equivalent way is by calling the constructor directly:
- EERef ref( 0 );
- ***/
-
- /** Using the reference **/
-
- /***
- Updating cell data.
- To prevent unnecessary wear on the EEPROM cells
- this function will only write the data when it
- is different to what is already stored.
- ***/
-
- ref.update( 44 ); //May write 44 if not present.
- ref.update( 44 ); //This second call will not write anything.
-
- /***
- Assign values directly to the EEPROM cell.
-
- You can use any form of assignment that would otherwise be available
- to a standard uint8_t:
-
- *=
- /=
- +=
- -=
- ^=
- %=
- &=
- |=
- <<=
- >>=
-
- ***/
-
- ref = 4; /***
- Take care to notice, this changes the EEPROM cell data, it does not
- change the index of the cell referenced by 'ref'.
-
- Only the initial declaration like 'EERef ref = 0;' will set the address.
- Using an assignment anywhere else modifies the referenced cell.
- To modify the referenced address after declaring your variable see below.
- ***/
-
- /***
- Changing the referenced object.
- The class has a member named 'index' which is an integer you can modify.
- ***/
-
- ref.index++; //Move reference to the next cell.
-
-
- /***
- Grouping of references.
-
- Using EERef objects you can create a contiguous array referencing
- non-contiguous EEPROM cells.
- ***/
-
- EERef array[] = { 0, 20, 40, 60, 80 };
-
-
-} //End of setup function.
-
-void loop(){} \ No newline at end of file
diff --git a/libraries/EEPROM/examples/eeprom_update/eeprom_update.ino b/libraries/EEPROM/examples/eeprom_update/eeprom_update.ino
index dbf05ec..831056f 100644
--- a/libraries/EEPROM/examples/eeprom_update/eeprom_update.ino
+++ b/libraries/EEPROM/examples/eeprom_update/eeprom_update.ino
@@ -14,7 +14,7 @@
#include <EEPROM.h>
/** the current address in the EEPROM (i.e. which byte we're going to write to next) **/
-int addr = 0;
+int address = 0;
void setup(){ /** EMpty setup **/ }
@@ -32,13 +32,13 @@ void loop()
these values will remain there when the board is
turned off.
***/
- EEPROM.update(addr, val);
+ EEPROM.update(address, val);
/***
- The function EEPROM.update(addr, val) is equivalent to the following:
+ The function EEPROM.update(address, val) is equivalent to the following:
- if( EEPROM.read(addr) != val ){
- EEPROM.write(addr, val);
+ if( EEPROM.read(address) != val ){
+ EEPROM.write(address, val);
}
***/
@@ -54,15 +54,15 @@ void loop()
Rather than hard-coding the length, you should use the pre-provided length function.
This will make your code portable to all AVR processors.
***/
- addr = addr + 1;
- if(addr == EEPROM.length())
- addr = 0;
+ address = address + 1;
+ if(address == EEPROM.length())
+ address = 0;
/***
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.
- ++addr &= EEPROM.length() - 1;
+ ++address &= EEPROM.length() - 1;
***/
delay(100);