I have 7 float variables.
float temperature, differential, calibration,hta,lta,hha,lha;
I want to store them all on the EEPROM memory, how do I calculate the addresses given that there type is float.
Thanks!
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It only takes a minute to sign up.
Sign up to join this communitycreate a struct and store the struct
#include <EEPROM.h>
const int DATA_ADDR = 0;
struct MyData {
float temperature, differential, calibration,hta,lta,hha,lha;
};
MyData data;
void setup() {
data.temperature = 1.2;
EEPROM.put(DATA_ADDR, data);
EEPROM.get(DATA_ADDR, data);
}
void loop() {
}
With the sizeof
function:
int nrOfBytesOfTemperature = sizeof(temperature);
You can also use directly a type:
int nrOfBytesOfFloat = sizeof(float);