52 lines
1.3 KiB
C++
52 lines
1.3 KiB
C++
#include "EEPROM.h"
|
|
|
|
/*
|
|
|
|
How the EEPROM is used:
|
|
|
|
|
|
First byte: shot counter offset
|
|
Second byte: hit counter offset
|
|
|
|
Each counter is a 32-bit unsigned integer (4 bytes). When it reaches a treshold
|
|
which is < 100,000 (the recommended EEPROM cell write limit) a new offset is calculated.
|
|
This way we ensure no cell is written over 100,000 times (assuming the EEPROM is
|
|
new) and you can click away until you run out of EEPROM.
|
|
|
|
|
|
For initialisation set ShotCounterOffset and HitCounterOffset to
|
|
different values. Keep in mind that Offset * 4 must not be greater than
|
|
the amount of available EEPROM!
|
|
|
|
Shot/HitCounterInitial defines the default value to write for
|
|
each counters.
|
|
|
|
*/
|
|
#define ShotCounterOffset 0
|
|
#define HitCounterOffset 1
|
|
|
|
#define ShotCounterInitial 0
|
|
#define HitCounterInitial 0
|
|
|
|
#define counterLocation(offset) 2 + (offset * sizeof(uint32_t))
|
|
|
|
void setup()
|
|
{
|
|
EEPROM.update(0, ShotCounterOffset);
|
|
EEPROM.update(1, HitCounterOffset);
|
|
|
|
EEPROM.put(counterLocation(ShotCounterOffset), (uint32_t)ShotCounterInitial);
|
|
EEPROM.put(counterLocation(HitCounterOffset), (uint32_t)HitCounterInitial);
|
|
|
|
pinMode(LED_BUILTIN, OUTPUT);
|
|
}
|
|
|
|
|
|
void loop()
|
|
{
|
|
digitalWrite(LED_BUILTIN, HIGH);
|
|
delay(1000);
|
|
digitalWrite(LED_BUILTIN, LOW);
|
|
delay(1000);
|
|
}
|