I have a problem with part of my program.
maybe someone knows why he stops writing the data to the EEPROM.
/*
SERIAL output
eeprom goed :35263
eeprom goed :42463
eeprom goed :49663
eeprom goed :56863
eeprom goed :64063
eeprom fout :71263 <- this is not good
eeprom fout :78463
eeprom fout :85663
eeprom fout :92863
*/
#include <EEPROMex.h>
const int maxAllowedWrites = 20; // eeprom
const int memBase = 140; // eeprom
long uvlamp_sec;
int uvlamp_timer = 0;
int addressInt_uvlamp;
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
delay(100);
EEPROM.setMemPool(memBase, EEPROMSizeUno);
EEPROM.setMaxAllowedWrites(maxAllowedWrites);
//----- adressen toekennen aan de eeprom variable. ------
addressInt_uvlamp = EEPROM.getAddress(sizeof(long));
uvlamp_timer=0;
uvlamp_sec = 0;
if (EEPROM.readInt(addressInt_uvlamp) < 1) { // wegschrijven data naar eeprom
EEPROM.writeInt(addressInt_uvlamp,uvlamp_sec);
}
else { // lezen data van eeprom
uvlamp_sec=EEPROM.readInt(addressInt_uvlamp);
}
}
// the loop routine runs over and over again forever:
void loop() {
timerteller();
delay(1);
}
void timerteller()
{
// uv lamp teller
// Serial.println("UV1");
uvlamp_sec +=1;
uvlamp_timer +=1;
if (uvlamp_timer == 7200){ // om de hoeveel tijd de data word weggeschreven naar de eeprom
uvlamp_timer = 0;
while (!eeprom_is_ready());
cli();
EEPROM.writeInt(addressInt_uvlamp,uvlamp_sec);
sei();
if (EEPROM.readInt(addressInt_uvlamp) == uvlamp_sec) {
Serial.print("eeprom goed :");
}
else
{
Serial.print("eeprom fout :");
}
Serial.println(uvlamp_sec);
}
}