You can read from EEPROM indefinitely without hurting it.
You can also set a second location as a "calibrated" flag, and once you write to one location, write to the calibrated flag location so you know that it's set.
Adding EEPROM functionality is reasonably simple:
#include <EEPROM.h>
...
Read from:
EEPROM.get( location, variable );
Write to:
EEPROM.update( location, variable );
So if you wanted to set a threshold based on what it was before you lost power, here's some pseudo-code:
#include <EEPROM.h>
const int thresholdStorage = 55; //arbitrary number
unsigned int threshold = 65535; //Warning: 65k degrees will melt equipment but this is the default
void setup()
{
//Upon power-up or reset, will grab the last known value from thresholdStorage
//and assign it to the int "threshold".
EEPROM.get( thresholdStorage, threshold );
}
void loop()
{
if( condition for resetting threshold, say a button or whatever )
{
EEPROM.update( thresholdStorage, threshold );
}
//you'd have to define the pin configuration. You probably also want a hysteresis value there,
//otherwise if you're right at the threshold you'll click the relay on and off like a castanet dancer.
if( analogRead( temperatureSensor ) >= ( threshold + 10 ) )
{
digitalWrite( fanControlPin, HIGH );
}
if( analogRead( temperatureSensor ) <= ( threshold - 10 ) )
{
digitalWrite( fanControlPin, LOW );
}
}