Hello,
Currently I am working on a project that will switch relays for a given duration. To explain, a user will input the desired relay to switch open to closed (from an 8 channel relay) and its duration using Nextion touchscreen. There are a total of four countdown timers before the program is over.
Problem: The relays will switch open once its countdown timer is over as I wanted it to. However, sometimes the program does not work. As in, it will stop working midway of the countdown. I will have to reset the program and try again. There is no pattern to when it is successful or not ( it's 50/50 chance).
I am not sure whether this is a coding problem, faulty Arduino pins, or coding issue. I have attached the code below. The focus is on the loop statement but I attached the entire code for clarification. Any assistance or recommendations is greatly appreciated
void loop() {
nexLoop(nex_listen_list);
time1 = LP1;
time2 = LP2;
time3 = LP3;
time4 = LP4;
R1 = R_1;
R2 = R_2;
R3 = R_3;
R4 = R_4;
while ( (test1 == false) && (timeToStart == 0) ) { // Once the START is Initiated.
nexLoop(nex_listen_list);
}
if (timeToStart == 0) {
timeToStart = millis();
}
// Check if millis() falls within time range, and run function. If not, kill function.
if ( (millis() >= timeToStart) && (millis() < timeToStart + time1) ) {
resistorTest(R1);
}
// CODE REPEATS FOR DIFFERENT TIMES AND RESISTOR VALUES.
else if ( (millis() >= timeToStart + time1) && (millis() < timeToStart + time1 + time2) ) {
resistorTest(R2);
}
else if ( (millis() >= timeToStart + time1 + time2) && (millis() < timeToStart + time1 + time2 + time3) ) {
resistorTest(R3);
}
else if ( (millis() >= timeToStart + time1 + time2 + time3) && (millis() < timeToStart + time1 + time2 + time3 + time4) ) {
resistorTest(R4);
}
else {
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
test1 = false;
timeToStart = 0;
}
}
March_27_Load_Code.ino (12 KB)