Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save facchinm/93f52a9092d02b010d69 to your computer and use it in GitHub Desktop.
Save facchinm/93f52a9092d02b010d69 to your computer and use it in GitHub Desktop.
From d0ce7cd7f072aa6cd641a2110b2f269986875f7b Mon Sep 17 00:00:00 2001
From: Martino Facchin <[email protected]>
Date: Fri, 20 Mar 2015 13:07:38 +0100
Subject: [PATCH] Fix examples on eeprom library v2
---
.../EEPROM/examples/eeprom_crc/eeprom_crc.ino | 4 +-
.../EEPROM/examples/eeprom_get/eeprom_get.ino | 4 +-
.../examples/eeprom_iteration/eeprom_iteration.ino | 19 +----
.../examples/eeprom_pointer/eeprom_pointer.ino | 74 -----------------
.../EEPROM/examples/eeprom_put/eeprom_put.ino | 15 ++--
.../EEPROM/examples/eeprom_read/eeprom_read.ino | 6 +-
.../examples/eeprom_reference/eeprom_reference.ino | 93 ----------------------
7 files changed, 15 insertions(+), 200 deletions(-)
delete mode 100644 hardware/arduino/avr/libraries/EEPROM/examples/eeprom_pointer/eeprom_pointer.ino
delete mode 100644 hardware/arduino/avr/libraries/EEPROM/examples/eeprom_reference/eeprom_reference.ino
diff --git a/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino b/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino
index 40b08bd..2535902 100644
--- a/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino
+++ b/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino
@@ -38,10 +38,10 @@ 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;
}
return crc;
-}
\ No newline at end of file
+}
diff --git a/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_get/eeprom_get.ino b/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_get/eeprom_get.ino
index 58475fd..782d3bb 100644
--- a/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_get/eeprom_get.ino
+++ b/hardware/arduino/avr/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: " );
@@ -60,4 +60,4 @@ void secondTest(){
Serial.println( customVar.name );
}
-void loop(){ /* Empty loop */ }
\ No newline at end of file
+void loop(){ /* Empty loop */ }
diff --git a/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino b/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino
index a2d825c..a836da9 100644
--- a/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino
+++ b/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino
@@ -50,24 +50,7 @@ void setup() {
EEPROM[ idx ] += 1;
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.
-void loop(){}
\ No newline at end of file
+void loop(){}
diff --git a/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_pointer/eeprom_pointer.ino b/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_pointer/eeprom_pointer.ino
deleted file mode 100644
index 637cdb7..0000000
--- a/hardware/arduino/avr/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/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_put/eeprom_put.ino b/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_put/eeprom_put.ino
index 7575768..ee2d6a9 100644
--- a/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_put/eeprom_put.ino
+++ b/hardware/arduino/avr/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);
@@ -30,13 +36,6 @@ void setup(){
Serial.println("Written float data type!");
/** 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,
@@ -50,4 +49,4 @@ void setup(){
Serial.print( "Written custom data type! \n\nView the example sketch eeprom_get to see how you can retrieve the values!" );
}
-void loop(){ /* Empty loop */ }
\ No newline at end of file
+void loop(){ /* Empty loop */ }
diff --git a/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino b/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino
index 8567ed7..f028cca 100644
--- a/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino
+++ b/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino
@@ -42,9 +42,9 @@ 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
diff --git a/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_reference/eeprom_reference.ino b/hardware/arduino/avr/libraries/EEPROM/examples/eeprom_reference/eeprom_reference.ino
deleted file mode 100644
index bcf84d6..0000000
--- a/hardware/arduino/avr/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
--
2.3.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment