Retained Memory Tips

You are missing what I am saying - I’m my view whether a battery is or isn’t connected - the first time the code is run - the value should be 0 - then after that point and as long as battery/power is connected - the value will be retained as its last set value.

Using the above example - with or without a battery connected the first time the code is run it is never 0. as expected it does increment from what ever value it first shows.

STARTUP(System.enableFeature(FEATURE_RETAINED_MEMORY)); 
retained int savedValue = 0; 
void setup() {
 Serial.begin(9600);
} 

void loop() { 
Serial.printlnf(“savedValue=%d”, savedValue++); 
delay(1000);
}
1 Like