Ok I found it.
Well I received some help but it's finally working.
Except for one thing.
My millis is not equal to 1 second. (I will put that question in another post)
void LcdCounter(){
CounterMillis = millis();
if (CounterMillis - CounterMillis1 >= interval2) {
if (a < 40 && purge == 0 && stateRELAY1 == HIGH) // value of 40 for testing purpose.
{ // The final goal will be 360 seconds
a ++;
lcd_2.setCursor(11, 1);
lcd_2.print(a);
Serial.println(CounterMillis); // for debug millis
Serial.println(CounterMillis1); // for debug millis
}
else
{
if (purge == 1){
a = 0;
purge = 0;
lcd_2.setCursor(11, 1);
lcd_2.print(F(" "));
}
if (a >= 40) // value of 40 for testing purpose.
// The final goal will be 360 seconds
{
stateRELAY1 = LOW;
stateRELAY2 = LOW;
stateRELAY3 = LOW;
lcd_2.setCursor(11, 1);
lcd_2.print(F("Purge"));
}
}
CounterMillis1 = CounterMillis;
}
}