I need to add a counter to my project.
(I posted about different parts of it in the last few weeks and this is sort of a new question)
My project is controling relay with buttons and sensors values conditions and those parts of the code work well.
I need to add a counter to my code and I want to see it counting on my lcd display.
I want it to count until it reach 360 and then "stateRELAY1 = LOW"
The counter need to start when a value reach 20. This value will reach 20 only for a few seconds BUT the counter need to continue counting even if the value is back below 20.
I tried with an "if" but since the "if" exist only for a few second my counter stop before it reach 360.
This is the part of the code that I tried and like I said it does count but only for the time
that the flowRate is bigger than 20.
void counter(){
if (flowRate > 20)
{
a ++;
lcd_2.setCursor(11, 1);
lcd_2.print(a);
}
}
When this will work I will want the following:
When flowRate is bigger than 20, start counting and lcd.print it until it reached 360 and when it's done, put stateRELAY1 to LOW and reset counter to 0 until flowRate is bigger than 20 again.
All this without stoping the rest of my code working.
My goal is to use this as a simple Dead Man Switch but I need to see the counting on the LCD display and because the flow sensor will normally see a Flow within every 360 counts, my RELAY1 will stay ON unless the flow doesn't work.
I hope my explanation are enough for the question. I didn't want to post all the code that is very long since my problem is only about counting.
I'm still learning coding and stuff with Arduino and sometime it's hard to know how to asked the good question to get good answers.
I have no problem about paying. The best way for me to learn right now is by example or with a teacher. I check around here in Montreal for Arduino "coding" courses and the only thing I found was 3 days introduction and this is really not enough for what I'm doing.
I didn't know about the Gigs and Collaborations sections in the forum, I will go to see. Yesterday I posted my project on a site called Guru.com to hire someone to help me. I will see what kind of answers I get.
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;
}
}