/*
Forum: https://forum.arduino.cc/t/beginner-needs-help-with-debounce-logic/1425853/145
Wokwi: https://wokwi.com/projects/455596401956786177
Previous version
Wokwi: https://wokwi.com/projects/455395245774614529
2026/02/10
ec2021
Change to previous version:
Changed const offSet to int _offSet in Class and
have it calculated from the size of _actEntry
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() {
Serial.begin(115200);
if (myEE.noMagicFound()){
Serial.println("No magic number found ...");
} else {
Serial.println("Magic number found!");
};
delay(3000);
myEE.init(maxCount, maxWriteCount);
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());
}