/*
Forum: https://forum.arduino.cc/t/beginner-needs-help-with-debounce-logic/1425853/145
Wokwi: https://wokwi.com/projects/455395245774614529
Previous version
Wokwi: https://wokwi.com/projects/455334017789551617
2026/02/08
ec2021
Change to previous version:
added a line to int32_t EEClass::updateActCount(uint32_t actCount) that avoids
storing a value to EEPROM that is already stored there
The file EEClass.h provides a class that allows to store and read a
32 Bit counter. Each write access is stored. Depending on the
initialization of the class the address where the data are stored
is moved to the next place in EEPROM storage.
Any count value given as a parameter to .updateActCount() will
be restricted to maxCount and returned by this function.
By using
actCount = myEE.updateActCount(actCount);
the actual value that is stored can be monitored.
When the maximum number of entries is reached the class will start
with entry = 0 again;
The required functions are
//Declare the class
EEClass myEE;
//Init the class
myEE.init(maxCount, maxWriteCount);
// Create some counter
uint32_t actCount = 100;
// Store the counter in EEPROM
// and check if it was affected by maxCount
actCount = myEE.updateActCount(actCount);
// Read the actual counter value
actCount = myEE.readActCount();
*/
#include "EEClass.h"
constexpr uint32_t maxWriteCount {100};
constexpr uint32_t maxCount {1100};
EEClass myEE;
void setup() {
myEE.init(maxCount, maxWriteCount);
Serial.begin(115200);
Update(999+2);
}
void loop() {
// put your main code here, to run repeatedly:
}
void Update(int c){
for (int i = 1; i <= c; i++){
myEE.updateActCount(i);
printActCount();
}
}
void printActCount() {
uint32_t actCount = myEE.readActCount();
Serial.print("Index\t");
Serial.print(myEE.getIndex());
Serial.print("\tCount\t");
Serial.print(actCount);
Serial.print("\tWriteCount\t");
Serial.println(myEE.getWriteCount());
}