1. Reference   Language | Libraries | Comparison | Changes

        EEPROM

        get()

        Description

        Read any data type or object from the EEPROM.

        Syntax

        EEPROM.get(address, data)

        Parameters

        address: the location to read from, starting from 0 (int)

        data: the data to read, can be a primitive type (eg. float) or a custom struct

        Returns

        A reference to the data passed in

        Example


        #include <EEPROM.h>

        struct MyObject{
          float field1;
          byte field2;
          char name[10];
        };

        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 );
          while (!Serial) {
            ; // wait for serial port to connect. Needed for Leonardo only
          }
          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.

          // get() can be used with custom structures too.
          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 );
        }

        void loop(){ /* Empty loop */ }
         

        See also

        Reference Home

        Corrections, suggestions, and new documentation should be posted to the Forum.

        The text of the Arduino reference is licensed under aCreative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.

            1. http://www.sydqzl4a.tw | http://m.sydqzl4a.tw | http://wap.sydqzl4a.tw | http://3g.sydqzl4a.tw | http://4g.sydqzl4a.tw | http://5g.sydqzl4a.tw | http://mobile.sydqzl4a.tw | http://vip.sydqzl4a.tw | http://ios.sydqzl4a.tw | http://anzhuo.sydqzl4a.tw | http://4aa0.sydqzl4a.tw | http://9a2.sydqzl4a.tw | http://971a7f.sydqzl4a.tw | http://0.sydqzl4a.tw | http://b1.sydqzl4a.tw | http://87.sydqzl4a.tw | 那好吧1024版本下载地址