John
That worked like a charm. I am using this with an encoder that is setting the Target. In the past I had to load the code twice for every virgin unit. I wish you taught me this earlier... than you,
Mitch
Here is my code with the encoder
#include <EEPROM.h>
float Target;
float AddToTarget;
#include <Encoder.h>
long positionKnob = -999;
long newKnob;
Encoder Knob(18, 19); // 18 is Yellow 19 is Green
void setup()
{
Serial.begin(115200);
while (!Serial) {}
Serial.println();
EEPROM.get(0, Target);
Serial.print(F("Read value of Target is "));
Serial.println (Target);
if (isnan(Target))
{
Serial.println(F("Target is 'nan' so initialize."));
Target = 8.88;
Serial.print(F("Initialized value of Target is "));
Serial.println (Target);
EEPROM.put(0, Target);
}
}
void loop(){ /* Empty loop */
newKnob = Knob.read();
if (newKnob != positionKnob) {
positionKnob = newKnob;
AddToTarget = (newKnob / 10.0);
Target = (Target + AddToTarget);
Target = constrain(Target, 1, 10000);
Serial.print(" KNOB = ");
Serial.println(newKnob);
Serial.print(" Target = ");
Serial.print(Target, 2);
Serial.println();
Knob.write(0);
EEPROM.put(0, Target);
}
Serial.println (Target);
delay (500);
}