Hi all, I'm pretty new to Arduinos but have some level of familiarity from a few years back. I am running into an issue in my code, and I cannot quite figure out what is wrong.
I am writing a program where a value is being measured. If the value is above the desired threshold for a pre-determined amount of time, then a rgb light will display red. If the value stays below the threshold for about 30 seconds, then a green light will be displayed, but if the value goes back above the threshold, then the timer resets for green. in the background the light will display blue if either the red or green count is not met.
The green count and light seem to be working as intended, however there seems to be an issue with the red count when testing at values greater than 10 minutes. For shorter time periods (1-6 minutes) the red light displays at the appropriate time. In a trial I've noticed the red count value will all of the sudden jump to a very large value. I'm a little puzzled by this and if anyone has any suggestions on how to alter my code they would be greatly appreciated.
Thanks.
//Setting 3
while (analogRead(A2) > 990) {
if (analogRead(A0) <= 612.98) {
countG3 = countG3 + 1;
Serial.println(countG3);
}
if (analogRead(A0) > 612.98) {
countR3 = countR3 + 1;
Serial.println(countR3);
}
if (countG3 >= 3000) { //30 seconds
digitalWrite(3, LOW);
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
if (analogRead(A0) > 612.98) {
countG3 = 0;
}
} else if (countR3 >= 180000) { //30 minutes
digitalWrite(3, LOW);
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
} else {
digitalWrite(3, HIGH);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
}
delay(10);
}