I am working on a counter project using esp32 in which I want to store the value of counter in esp32 using preferences library when a button is pressed. It works when the code is
#include <Arduino.h>
#include<Preferences.h>
Preferences preferences;
int val = 0;
void setup(){
Serial.begin(115200);
preferences.begin("counter", false);
val = preferences.getUInt("val",0);
val++;
Serial.println(val);
preferences.putUInt("val",val);
}
void loop(){
}
Hey @ZX80 , yeah you're right. So when the code the runs it should store val + 1 right? but it is not storing and getUInt gives the old value. But If use the 1st code that I posted ,every time when I reset esp32 val is getting incremented and storing