Hello everyone,
I am starting to run a project for the purpose of long-time 8 week test. The idea is to turn 2 outputs alternately via 2-line relay.
I have written a simple code for that and implemented an integer counting how many cycles has passed outputing the value on the LCD (simple TM1637).
I'd just run that test continously forever, but I am afraid that there might be some cshortages in power supply during this test and I would probably lose information about how many cycles passed at some point.
I suppose as well, that for the safety reasons I'd need to start again this test every morning when I am at work and stop it after it.
The solution for that I came up with was to write this licznik_cykli integer each time after the cycle passed into the EEPROM memory. Unfortunately it would be 16-bit integer, not a short one, so there is also case of Write/ReadLong.
The question is, how to write the code so it would read the EEPROM at the start (with t=0 values on bytes of EEPROM being 0) and how to write the licznik_cykli value to the EEPROM at the end of the loop "loop" as it is an integer. I found the example of it on: playground.arduino.cc/Code/EEPROMReadWriteLong but I am not sure if I read it the right way.
#define DIO 34
TM1637Display display(CLK, DIO);
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
pinMode(52, OUTPUT);
pinMode(22, OUTPUT);
pinMode(24, OUTPUT);
pinMode(30, INPUT);
display.setBrightness(0x0f);
}
// the loop function runs over and over again forever
void loop() {
int nx = 0;
int licznik_cykli = 0;
int i;
int start = 0;
for (; licznik_cykli != 211;) { //docelowo 211 cykli dziennie
display.showNumberDec(licznik_cykli,true, 4, 0);
while (nx < 4) {
digitalWrite(22, HIGH);
digitalWrite(LED_BUILTIN, HIGH);
delay(4000);
digitalWrite(LED_BUILTIN, LOW);
digitalWrite(22, LOW);
delay(12000);
++nx;
}
while (nx == 4) {
digitalWrite(22, LOW);
digitalWrite(24, HIGH);
digitalWrite(52, HIGH);
delay(12000);
digitalWrite(24, LOW);
digitalWrite(52, LOW);
++nx;
}
while (nx > 4) {
delay(36000);
++licznik_cykli;
nx = 0;
}
}
}