Consider:
#include <EEPROM.h>
byte guifactor1 = 1;
byte guifactor2 = 2;
byte guifactor3 = 3;
byte guifactor4 = 4;
byte guifactorgas = 5;
byte guifactorwater = 6;
volatile unsigned long count1factor;
volatile unsigned long count2factor;
volatile unsigned long count3factor;
volatile unsigned long count4factor;
volatile unsigned long countgasfactor;
volatile unsigned long countwaterfactor;
void loop(){
if (guifactor1 > -1){
EEPROM.write(1, guifactor1);
EEPROM.commit();
count1factor = EEPROM.read(1);
Serial.println(count1factor);
}
if (guifactor2 > -1){
EEPROM.write(2, guifactor2);
EEPROM.commit();
count2factor = EEPROM.read(2);
Serial.println(count2factor);
}
if (guifactor3 > -1){
EEPROM.write(3, guifactor3);
EEPROM.commit();
count3factor = EEPROM.read(3);
Serial.println(count3factor);
}
if (guifactor4 > -1){
EEPROM.write(4, guifactor4);
EEPROM.commit();
count4factor = EEPROM.read(4);
Serial.println(count4factor);
}
if (guifactorgas > -1){
EEPROM.write(5, guifactorgas);
EEPROM.commit();
countgasfactor = EEPROM.read(5);
Serial.println(countgasfactor);
}
if (guifactor1 > -1){
EEPROM.write(6, guifactorwater);
EEPROM.commit();
countwaterfactor = EEPROM.read(6);
Serial.println(countwaterfactor);
}
}
void setup(){
}
The problem I have with my code is that it either doesn’t write the value to the EEPROM or it doesn’t read the value as it doesn’t print anything to the monitor.
I expected to read 1 2 3 4 5 6 from the monitor as I write the bytes to the EEPROM and then transfer the value to the unsigned long and print the variable.
guifactor1
and its siblings will be implicitly initialized with zero (since they are global and you don't explicitly initialize them). Checkingguifactor1 > -1
won't ever be true, since you initialized them to zero and don't change them anymore, and also they areunsigned long
s, so they cannot ever carry a negative value. You should rethink the logic of your program.