Go Down

Topic: Store floats in EEPROM (Read 1 time) previous topic - next topic

aspurge

Hello Everyone,

I'm working on a prototype system that involves a bunch of time settings (eight to be exact) and I'd like to be able to store these settings as presets in EEPROM.

The time settings are relatively precise and can range from 0.01-2.00 seconds, which require me to declare the time variables as floats. I want to be able to save a full set of time settings (all eight time settings) in EEPROM to be accessed later, but I'm having trouble doing so. I've tried to multiply the floats by 100 and convert them to ints to be saved, but no luck.

Just to provide some more details about the system, I'll elaborate. I want to have five presets and EACH preset will have eight time settings. The time settings are just different variables of the total cycle. The system will perform different functions for a certain amount of time based on the time settings, but the total cycle will be an aggregate of the eight different times.

Example:

Preset 1:
STAGE 1: 0.30
STAGE 2: 0.60
STAGE 3:1.30
STAGE 4: 0.55
STAGE 5: 1.60
STAGE 6: 0.20
STAGE 7: 0.80
STAGE 8: 1.10

Preset 2:
STAGE 1: 1.30
STAGE 2: 1.60
STAGE 3: 0.42
STAGE 4: 0.05
STAGE 5: 1.10
STAGE 6: 1.20
STAGE 7: 0.10
STAGE 8: 0.50

I want to be able to store Preset 1 and Preset 2 in EEPROM, just to sum things up.

Any suggestions would be appreciated.

Thanks!

groundfungus

Time from 0.01 to 2.00 could be represented by one byte if you multiply by 100 before saving and doing a divide on retrieval.

aspurge

Hmmm, I tried to do that but wasn't able to get it to work.

Do you have an example?


groundfungus

I am new to C so not fluent at all.  I tried the code below using serial monitor and it seemed to work as far as change the data types.


Code: [Select]
float timeToSave = 1.22;
byte timeByte;
float retrievedTime;

timeByte = byte(timeToSave * 100);
// save byte to EEPROM

//retrieve timByte
retrievedTime = float(timeByte / 100.00);

tylernt

http://playground.arduino.cc/Code/EEPROMWriteAnything

Go Up