#include<EEPROM.h>voidsetup(){for(inti=0;i<255;i++){// this performs as EEPROM.write(i, i)
EEPROM.update(i,i);}for(inti=0;i<255;i++){// write value "12" to cell 3 only the first time
// will not write the cell the remaining 254 times
EEPROM.update(3,12);}}voidloop(){}
#include<EEPROM.h>structMyObject{floatfield1;bytefield2;charname[10];};voidsetup(){floatf=0.00f;//Variable to store data read from EEPROM.
inteeAddress=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'.
MyObjectcustomVar;//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);}voidloop(){/* Empty loop */}
#include<EEPROM.h>structMyObject{floatfield1;bytefield2;charname[10];};voidsetup(){Serial.begin(9600);while(!Serial){;// wait for serial port to connect. Needed for native USB port only
}floatf=123.456f;//Variable to store in EEPROM.
inteeAddress=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. **///Data to store.
MyObjectcustomVar={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!");}voidloop(){/* Empty loop */}