Hello Everyone
I hope that all of you are doing well. I've written the following algorithm function to read and convert multiple values from EEPROM to it's original values for when the value is larger then 255. You'll need the write function to be able to implement the read function, but if anyone is interested I will share the code as soon as I'm done.
Now "Example 1" was my first attempt and when I looked over it, it didn't really make sense to me. It seemed to me that when the while loop is entered then the EEPROM is not going to read anything meaningful. I say this since no addresses have been assigned to Even_Uneven_Detector_Address, Multiplier_Address and Variable_Address to read the values and to assign them to specific variables at the stage of reading from the EEPROM.
Since then I've changed the function so that it looks as in "Example 2". In "Example 2" the addresses is assigned with a first case function and then the values are read from the respective addresses and the values are then assigned using a second case function to the respective variables
The code in my second example makes sense to me, I just want to confirm what I'm saying is correct or whether I'm going a bit way overboard and that I could have just used the code as in my first example? Just double checking here. Thanks for taking the time in advance
Example 1:
//*********************************************************************************************************************************************************
//********************************************** Reading From EEPROM Function ******************************************************
//*********************************************************************************************************************************************************
void Read_From_EEPROM()
{
Stage_Storage_Selector = 0;
while ( Stage_Storage_Selector <= 2 )
{
Even_Uneven_Detector = EEPROM.read(Even_Uneven_Detector_Address);
Multiplier = EEPROM.read(Multiplier_Address);
Variable = EEPROM.read(Variable_Address);
if ( Even_Uneven_Detector == 2 && Multiplier == 2 )
{
Variable = ((Variable * 2) - 1);
}
if ( Even_Uneven_Detector == 1 && Multiplier == 2 )
{
Variable = Variable * 2;
}
switch (Stage_Storage_Selector)
{
case 0:
PREH_Temp = Variable;
PREH_Temp_Address = Variable_Address;
PREH_Multiplier = Multiplier;
PREH_Multiplier_Address = Multiplier_Address;
PREH_Even_Uneven_Detector = Even_Uneven_Detector;
PREH_Even_Uneven_Detector_Address = Even_Uneven_Detector_Address;
break;
case 1:
HEAT_Temp = Variable;
HEAT_Temp_Address = Variable_Address;
HEAT_Multiplier = Multiplier;
HEAT_Multiplier_Address = Multiplier_Address;
HEAT_Even_Uneven_Detector = Even_Uneven_Detector;
HEAT_Even_Uneven_Detector_Address = Even_Uneven_Detector_Address;
break;
case 2:
SLDR_Temp = Variable;
SLDR_Temp_Address = Variable_Address;
SLDR_Multiplier = Multiplier;
SLDR_Multiplier_Address = Multiplier_Address;
SLDR_Even_Uneven_Detector = Even_Uneven_Detector;
SLDR_Even_Uneven_Detector_Address = Even_Uneven_Detector_Address;
break;
}
Stage_Storage_Selector++;
}
}
Example 2:
void Read_From_EEPROM()
{
Stage_Storage_Selector = 0;
while ( Stage_Storage_Selector <= 2 )
{
switch (Stage_Storage_Selector) // First case is to read and assign the correct addresses to the various variables
{
case 0:
PREH_Temp_Address = Variable_Address;
PREH_Multiplier_Address = Multiplier_Address;
PREH_Even_Uneven_Detector_Address = Even_Uneven_Detector_Address;
break;
case 1:
HEAT_Temp_Address = Variable_Address;
HEAT_Multiplier_Address = Multiplier_Address;
HEAT_Even_Uneven_Detector_Address = Even_Uneven_Detector_Address;
break;
case 2:
SLDR_Temp_Address = Variable_Address;
SLDR_Multiplier_Address = Multiplier_Address;
SLDR_Even_Uneven_Detector_Address = Even_Uneven_Detector_Address;
break;
}
Even_Uneven_Detector = EEPROM.read(Even_Uneven_Detector_Address);
Multiplier = EEPROM.read(Multiplier_Address);
Variable = EEPROM.read(Variable_Address);
if ( Even_Uneven_Detector == 2 && Multiplier == 2 )
{
Variable = ((Variable * 2) - 1);
}
if ( Even_Uneven_Detector == 1 && Multiplier == 2 )
{
Variable = Variable * 2;
}
switch (Stage_Storage_Selector)
{
case 0:
PREH_Temp = Variable;
PREH_Multiplier = Multiplier;
PREH_Even_Uneven_Detector = Even_Uneven_Detector;
break;
case 1:
HEAT_Temp = Variable;
HEAT_Multiplier = Multiplier;
HEAT_Even_Uneven_Detector = Even_Uneven_Detector;
break;
case 2:
SLDR_Temp = Variable;
SLDR_Multiplier = Multiplier;
SLDR_Even_Uneven_Detector = Even_Uneven_Detector;
break;
}
Stage_Storage_Selector++;
}
}