EEPROM:put()
從 YFRobotwiki
|
put()
描述 向EEPROM中寫入任何類型數據或對象。
EEPROM.put(address, data)
address: 寫入的位置,從0開始 (int 整型) data: 寫入的數據,可以是一個基本類型(例如:float 浮點型)或者是一個自定義的結構體。
數據傳遞的引用
這個函數使用EEPROM.update()來執行寫數據,所以如果值沒有改變不會重複寫入的。 示例
#include <EEPROM.h>
struct MyObject{
float field1;
byte field2;
char name[10];
};
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.
//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 too.
//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.println( "Written custom data type!")
Serial.println( "View the example sketch eeprom_get to see how you can retrieve the values!" );
}
void loop(){ /* Empty loop */ }
|
更多建議和問題歡迎反饋至 YFRobot論壇