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 --- .../EEPROM/examples/eeprom_put/eeprom_put.ino | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 libraries/EEPROM/examples/eeprom_put/eeprom_put.ino (limited to 'libraries/EEPROM/examples/eeprom_put') diff --git a/libraries/EEPROM/examples/eeprom_put/eeprom_put.ino b/libraries/EEPROM/examples/eeprom_put/eeprom_put.ino new file mode 100644 index 0000000..7575768 --- /dev/null +++ b/libraries/EEPROM/examples/eeprom_put/eeprom_put.ino @@ -0,0 +1,53 @@ +/*** + eeprom_put example. + + This shows how to use the EEPROM.put() method. + Also, this sketch will pre-set the EEPROM data for the + example sketch eeprom_get. + + Note, unlike the single byte version EEPROM.write(), + the put method will use update semantics. As in a byte + will only be written to the EEPROM if the data is actually + different. + + Written by Christopher Andrews 2015 + Released under MIT licence. +***/ + +#include + +void setup(){ + + Serial.begin(9600); + + float f = 123.456f; //Variable to store in EEPROM. + int eeAddress = 0; //Location we want the data to be put. + + + //One simple call, with the address first and the object second. + EEPROM.put( eeAddress, f ); + + 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, + 65, + "Working!" + }; + + eeAddress += sizeof(float); //Move address to the next byte after float 'f'. + + EEPROM.put( eeAddress, customVar ); + 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 -- 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 --- libraries/EEPROM/examples/eeprom_put/eeprom_put.ino | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'libraries/EEPROM/examples/eeprom_put') 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 +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, -- cgit v1.2.3-18-g5258 From d8656b8c5249c9d06cd8ed96b2061759ab69b5bf Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Tue, 24 Mar 2015 10:20:00 +0100 Subject: EEPROM: examples: fix Serial for board Leonardo --- libraries/EEPROM/examples/eeprom_put/eeprom_put.ino | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'libraries/EEPROM/examples/eeprom_put') diff --git a/libraries/EEPROM/examples/eeprom_put/eeprom_put.ino b/libraries/EEPROM/examples/eeprom_put/eeprom_put.ino index e99b4bd..186cf95 100644 --- a/libraries/EEPROM/examples/eeprom_put/eeprom_put.ino +++ b/libraries/EEPROM/examples/eeprom_put/eeprom_put.ino @@ -25,7 +25,10 @@ struct MyObject{ void setup(){ Serial.begin(9600); - + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + float f = 123.456f; //Variable to store in EEPROM. int eeAddress = 0; //Location we want the data to be put. -- cgit v1.2.3-18-g5258