J-M-L:
you can see the EEPROM as a line of boxes - each box can hold 1 byte. The put() function will look at how many bytes are needed for your parameter (for example 4 bytes for your float on a UNO) and if you ask to save your float starting at box #0 then it will fill Boxes #0 #1 #2 and #3.if you want to save a second element you want to make sure you don't store it in a box that has already a value, you need to start in box #4.
when you do
eeAddress += sizeof(float);this is exactly what you do: you take into account how many boxes were needed to store your float and you set the eeAddress to the next available box
thankyou for clearing that up, so far with the EEPROM.put() i have come up with this is this okay? im not sure because i know originally it was designed for use of floats in this example?
/***
eeprom_put example.
This shows how to use the EEPROM.put() method.
Also, this sketch will pre-set the EEPROM data for the
example sketch eeprom_get.
Note, unlike the single byte version EEPROM.write(),
the put method will use update semantics. As in a byte
will only be written to the EEPROM if the data is actually
different.
Written by Christopher Andrews 2015
Released under MIT licence.
***/
#include <EEPROM.h>
struct MyObject {
float field1;
byte field2;
char name[10];
};
void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
unsigned long t1ontimeDAY = 10700; /////
unsigned long t1offtimeDAY = 10000;
unsigned long t2ontimeDAY = 13400; /////
unsigned long t2offtimeDAY = 10000;
unsigned long t3ontimeDAY = 0; /////
unsigned long t3offtimeDAY = 0;
unsigned long t1ontimeNIGHT = 10000; /////
unsigned long t1offtimeNIGHT = 50000;
unsigned long t2ontimeNIGHT = 12400; /////
unsigned long t2offtimeNIGHT = 50000;
unsigned long t3ontimeNIGHT = 10; /////
unsigned long t3offtimeNIGHT = 10; //Variable to store in EEPROM
int eeAddress = 0; //Location we want the data to be put.
//One simple call, with the address first and the object second.
EEPROM.put(eeAddress, t1ontimeDAY);
EEPROM.put(eeAddress, t1offtimeDAY);
EEPROM.put(eeAddress, t2ontimeDAY);
EEPROM.put(eeAddress, t2offtimeDAY);
EEPROM.put(eeAddress, t3ontimeDAY);
EEPROM.put(eeAddress, t3offtimeDAY);
EEPROM.put(eeAddress, t1ontimeNIGHT);
EEPROM.put(eeAddress, t1offtimeNIGHT);
EEPROM.put(eeAddress, t2ontimeNIGHT);
EEPROM.put(eeAddress, t2offtimeNIGHT);
EEPROM.put(eeAddress, t3ontimeNIGHT);
EEPROM.put(eeAddress, t3offtimeNIGHT);
Serial.println("Written float data type!");
eeAddress += sizeof(long); //Move address to the next byte after float 'f'.
}
void loop() {
/* Empty loop */
}