#include <EEPROM.h>
// Initialwerte für die 4 Counter
int counter1 = 0;
int counter2 = 0;
int counter3 = 0;
int counter4 = 0;
// Speicheradressen im EEPROM
int eepromAddress1 = 0;
int eepromAddress2 = 1;
int eepromAddress3 = 2;
int eepromAddress4 = 3;
void setup() {
Serial.begin(9600);
// Counter aus dem EEPROM lesen
counter1 = EEPROM.read(eepromAddress1);
counter2 = EEPROM.read(eepromAddress2);
counter3 = EEPROM.read(eepromAddress3);
counter4 = EEPROM.read(eepromAddress4);
// Wenn der Wert im EEPROM ungültig ist (z.B. 255), dann auf 0 setzen
if (counter1 == 255) counter1 = 0;
if (counter2 == 255) counter2 = 0;
if (counter3 == 255) counter3 = 0;
if (counter4 == 255) counter4 = 0;
// Ausgabe der Counterwerte
Serial.print("Counter 1: ");
Serial.println(counter1);
Serial.print("Counter 2: ");
Serial.println(counter2);
Serial.print("Counter 3: ");
Serial.println(counter3);
Serial.print("Counter 4: ");
Serial.println(counter4);
}
void loop() {
// Beispiel: Counter um 1 erhöhen und im EEPROM speichern
counter1++;
counter2++;
counter3++;
counter4++;
EEPROM.write(eepromAddress1, counter1);
EEPROM.write(eepromAddress2, counter2);
EEPROM.write(eepromAddress3, counter3);
EEPROM.write(eepromAddress4, counter4);
// Ausgabe der aktuellen Counterwerte
Serial.print("Aktueller Counter 1: ");
Serial.println(counter1);
Serial.print("Aktueller Counter 2: ");
Serial.println(counter2);
Serial.print("Aktueller Counter 3: ");
Serial.println(counter3);
Serial.print("Aktueller Counter 4: ");
Serial.println(counter4);
delay(1000); // Warte 1 Sekunde
}