diff options
author | Federico Fissore <f.fissore@arduino.cc> | 2015-07-06 15:18:33 +0200 |
---|---|---|
committer | Federico Fissore <f.fissore@arduino.cc> | 2015-07-06 15:19:05 +0200 |
commit | b5a130afb51c971fd7ceca8834b6055f1eada253 (patch) | |
tree | d1e964f67822e9b3f10382573a9579c85b9c3e3f /libraries/EEPROM/examples/eeprom_get | |
parent | c13cf02651e178ea7941a82bee364d82c6b19b9c (diff) |
Examples: mass code format. See example_formatter.conf
Diffstat (limited to 'libraries/EEPROM/examples/eeprom_get')
-rw-r--r-- | libraries/EEPROM/examples/eeprom_get/eeprom_get.ino | 56 |
1 files changed, 29 insertions, 27 deletions
diff --git a/libraries/EEPROM/examples/eeprom_get/eeprom_get.ino b/libraries/EEPROM/examples/eeprom_get/eeprom_get.ino index 6620999..bbebc48 100644 --- a/libraries/EEPROM/examples/eeprom_get/eeprom_get.ino +++ b/libraries/EEPROM/examples/eeprom_get/eeprom_get.ino @@ -1,66 +1,68 @@ /*** eeprom_get example. - + This shows how to use the EEPROM.get() method. - + To pre-set the EEPROM data, run the example sketch eeprom_put. - This sketch will run without it, however, the values shown + This sketch will run without it, however, the values shown will be shown from what ever is already on the EEPROM. - + This may cause the serial object to print out a large string of garbage if there is no null character inside one of the strings loaded. - + Written by Christopher Andrews 2015 - Released under MIT licence. + Released under MIT licence. ***/ #include <EEPROM.h> -void setup(){ - +void setup() { + float f = 0.00f; //Variable to store data read from EEPROM. int eeAddress = 0; //EEPROM address to start reading from - - Serial.begin( 9600 ); + + Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } - Serial.print( "Read float from EEPROM: " ); + Serial.print("Read float from EEPROM: "); //Get the float data from the EEPROM at position 'eeAddress' - EEPROM.get( eeAddress, f ); - Serial.println( f, 3 ); //This may print 'ovf, nan' if the data inside the EEPROM is not a valid float. - + EEPROM.get(eeAddress, f); + Serial.println(f, 3); //This may print 'ovf, nan' if the data inside the EEPROM is not a valid float. + /*** As get also returns a reference to 'f', you can use it inline. E.g: Serial.print( EEPROM.get( eeAddress, f ) ); ***/ - - /*** - Get can be used with custom structures too. + + /*** + Get can be used with custom structures too. I have separated this into an extra function. ***/ - + secondTest(); //Run the next test. } -struct MyObject{ +struct MyObject { float field1; byte field2; char name[10]; }; -void secondTest(){ +void secondTest() { int eeAddress = sizeof(float); //Move address to the next byte after float 'f'. MyObject customVar; //Variable to store custom object read from EEPROM. - EEPROM.get( eeAddress, customVar ); - - Serial.println( "Read custom object from EEPROM: " ); - Serial.println( customVar.field1 ); - Serial.println( customVar.field2 ); - Serial.println( customVar.name ); + EEPROM.get(eeAddress, customVar); + + Serial.println("Read custom object from EEPROM: "); + Serial.println(customVar.field1); + Serial.println(customVar.field2); + Serial.println(customVar.name); } -void loop(){ /* Empty loop */ }
\ No newline at end of file +void loop() { + /* Empty loop */ +}
\ No newline at end of file |