0

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!

2 Answers 2

2

create 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() {

}
1

With the sizeof function:

int nrOfBytesOfTemperature = sizeof(temperature);

You can also use directly a type:

int nrOfBytesOfFloat = sizeof(float);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.