gerdal
1
Hello, I am struggled with eeprom can someone help me ,
I have 4 difrent int in my code that I calculate in loop.
Value= 154
valuea =785
valueb = 5
valuec = 200
valued= 650
I need to write this values to eeprom
I looked in the forum they are eeprom write anything or eeprom get or eepromput but I couldt find how to use it..
gerdal
3
yes but I cant figured .
I wat to to write all these in eeprom and when I need I want to call just the value of the int I chose
when I tried to use EEprom.write when I Make EEpprom.Read(valueb) the values comes difrent
when try to write I use eeprom.write(valuea,785)
The quick way
int address = 0;
EEPROM.put(address, valueA);
Serial.print("valueA stored at "); Serial.println(address);
address += sizeof(valueA);
EEPROM.put(address, valueB);
Serial.print("valueB stored at "); Serial.println(address);
address += sizeof(valueB);
...
...
To read it back, you need to know the address where a variable was saved; e.g. valueB was saved at address 2.
EEPROM.get(2, newVarB);
Serial.print("newVarB = "); Serial.println(newVarB);
You can also use
const int addressA = 0;
const int addressB = addressA + sizeof(int);
...
...
And write with
EEPROM.put(addressA, valueA);
Serial.print("valueA stored at "); Serial.println(addressA);
EEPROM.put(addressB, valueB);
Serial.print("valueB stored at "); Serial.println(addressB);
...
...
And to read it back
EEPROM.get(addressB, newVarB);
Serial.print("newVarB = "); Serial.println(newVarB);
pcbbc
5
gerdal:
yes but I cant figured .
I wat to to write all these in eeprom and when I need I want to call just the value of the int I chose
when I tried to use EEprom.write when I Make EEpprom.Read(valueb) the values comes difrent
when try to write I use eeprom.write(valuea,785)
Try put and get.
Read and write on read and write single bytes (0...255).
#include <EEPROM.h>
int Value = 154;
int valuea = 785;
int valueb = 5;
int valuec = 200;
int valued = 650;
const int addr_Value = 0;
const int addr_valuea = addr_Value + sizeof Value;
const int addr_valueb = addr_valuea + sizeof valuea;
const int addr_valuec = addr_valueb + sizeof valueb;
const int addr_valued = addr_valuec + sizeof valuec;
void setup()
{
Serial.begin(115200);
while (!Serial);
// Only needed once
EEPROM.put(addr_Value, Value);
EEPROM.put(addr_valuea, valuea);
EEPROM.put(addr_valueb, valueb);
EEPROM.put(addr_valuec, valuec);
EEPROM.put(addr_valued, valued);
int V, va, vb, vc, vd;
EEPROM.get(addr_Value, V);
EEPROM.get(addr_valuea, va);
EEPROM.get(addr_valueb, vb);
EEPROM.get(addr_valuec, vc);
EEPROM.get(addr_valued, vd);
Serial.println(V);
Serial.println(va);
Serial.println(vb);
Serial.println(vc);
Serial.println(vd);
}
void loop() {}