There is nothing worse than looking at a chip and wondering what it is doing. Every program needs to have an indicator that
gives the status of the program. The UNO and MINI have an on board LED for this purpose and it is designated as pin #13.
The easiest way to do this is a ditalWrite and a delay. All these delays can really slow down a program. Remember it takes
26 program loops for the battery voltage to stabilize. For this reason blinktime counter is used to initiate the blink sequence
every twenty loops. The first blink is always there just to indicate the program is running. One blink the voltage is fine.
If the voltage is just a little low, a second blink happens. Even lower voltage gives a third blink and a fourth blink indicates
that the relay is just about to turn off or has already. It is kinda clunky to do the code this way but it is understandable.
The fridge does this a slightly different way using program loop counts instead of delays.
// BLINKING LED STATUS DISPLAY
// The following is not necessary but provides useful information on how the program is running
// blinktime counts the number of program loops
blinktime = blinktime + 1;
// add one to the blink counter
if (blinktime > 20) blinktime = 0;
// reset counter when a certain count is reached
// blink display happens only when the count is 2
// FIRST BLINK - JUST TO SHOW THAT THE PROGRAM RUNNING
if (blinktime == 2 && blinktime == 2)digitalWrite(13, 1);
// pin #13 is the on board LED, 1 is ON
delay(20);
// delay 20 milliseconds, the time the LED is on
digitalWrite(13, 0);
// turns the LED off if it happens to be on so it blinks
// this inserts a delay between the next blink in blink mode
if (blinktime == 2)delay(300);
// delay 300 milliseconds, LONG DELAYS only in blink mode
// SECOND BLINK - IF SLIGHTLY UNDER VOLTAGE
if (blinktime == 2 && battery < 13400) digitalWrite(13, 1);
delay(20);
// delay 20 milliseconds
digitalWrite(13, 0);
// sets the LED off so it blinks
if (blinktime == 2)delay(300);
// delay 300 milliseconds
// THIRD BLINK - IF EVEN LOWER VOLTAGE
if (blinktime == 2 && battery < 12900) digitalWrite(13, 1);
delay(20);
// delay 20 milliseconds
digitalWrite(13, 0);
// sets the LED off so it blinks
if (blinktime == 2)delay(300);
// delay 300 milliseconds
// FOURTH BLINK - IF IT IS JUST ABOUT TO TURN OFF RELAY
if (blinktime == 2 && battery < 12500) digitalWrite(13, 1);
delay(20);
// delay 20 milliseconds
digitalWrite(13, 0);
// sets the LED off so it blinks
if (blinktime == 2)delay(300);
// delay 300 milliseconds
// A single blink indicates everything is normal