No it is a problem...
The integer of the reference # varies from 322 to 500 (so in this case it the above procedure needs to be done, if I am correctly understanding)
While the gas # varies from 500 to 1200. Which means I am taking more than one and more addresses
But I need to save these #s in an array which is proportional to the reference # and gas
meaning array[reference] = gas
So how can I know which address it is if each refernce # and gas amount is different entered by the user??
I don't know about the application and description of the needs, but simple way to get high and low byte would be like this.
If your integer is 1234, just do 1234/256=4
4 is the value of your highbyte
Then next you take (4256) out from your original int; 1234 - (4256) =210
210 is your lower byte.
Then, when you need to know the address your about to write these values.
If the pointer in the array is, lets say 51, so you have value 1234 in YourArray[51], you write it to eeprom;
EEPROM.write( (251) , lowByte );
EEPROM.write( ( (251) + 1) , highByte );
I'm a bit tired, so there's probably errors in my text, please, don't hesitate to say that was bull...it.
Cheers,
Kari
EDIT. I have never used eeprom library, that maybe wrong syntax...
You could put them in a simple header file - they are simple templates.
As long as you know how big your objects are, you can store and read back any size, up to the maximum size of the EEPROM on your processsor.
I'd probably recommend describing a single struct to store all the values you need to save, so a single call will save/restore all your values, though I'd probably rewrite "writeAnything" to only write a byte if it had changed (read it first to compare)
#include <EEPROM.h>
template <class T> int EEPROM_writeAnything(int ee, const T& value)
{
const byte* p = (const byte*)(const void*)&value;
int i;
for (i = 0; i < sizeof(value); i++)
EEPROM.write(ee++, *p++);
return i;
}
template <class T> int EEPROM_readAnything(int ee, T& value)
{
byte* p = (byte*)(void*)&value;
int i;
for (i = 0; i < sizeof(value); i++)
*p++ = EEPROM.read(ee++);
return i;
}
void setup()
{
Serial.begin(9600);
int reference = 323;
int gas = 1234;
int serial;
int serial1;
EEPROM_writeAnything(0, reference);
serial = EEPROM_readAnything(0,reference);
Serial.print(serial);
}
void loop()
{
}
2...
But how can it be that I am storing the reference # inside address 0 only?(I dont think it is...)
since if i write
serial = eeprom.read(0)
323 is not displayed