Thanks for the reply. Yes your example worked out well.
I managed to somewhat shorten and refine my code which seems to be working properly..... so far.
I'm sure there is more refining that can be done but will see how this works out for a bit.
int relays[] = {PIN_PUMP_1, PIN_ZONE_1, PIN_ZONE_2, PIN_ZONE_3, PIN_ZONE_4, PIN_ZONE_5, PIN_ZONE_6, PIN_ZONE_7, PIN_ZONE_8, PIN_ZONE_9, PIN_ZONE_10, PIN_ZONE_11, PIN_ZONE_12};
uint8_t *pumpORzone[] = {&RemoteXY.zone_1, &RemoteXY.zone_2, &RemoteXY.zone_3, &RemoteXY.zone_4, &RemoteXY.zone_5, &RemoteXY.zone_6, &RemoteXY.zone_7, &RemoteXY.zone_8, &RemoteXY.zone_9, &RemoteXY.zone_10, &RemoteXY.zone_11, &RemoteXY.zone_12};
int *zoneRunTime[] = {&RemoteXY.rTzone_1, &RemoteXY.rTzone_2, &RemoteXY.rTzone_3, &RemoteXY.rTzone_4, &RemoteXY.rTzone_5, &RemoteXY.rTzone_6, &RemoteXY.rTzone_7, &RemoteXY.rTzone_8, &RemoteXY.rTzone_9, &RemoteXY.rTzone_10, &RemoteXY.rTzone_11, &RemoteXY.rTzone_12};
uint8_t *pumpORzoneLED[] = {&RemoteXY.led_1_b, &RemoteXY.led_2_b, &RemoteXY.led_3_b, &RemoteXY.led_4_b, &RemoteXY.led_5_b, &RemoteXY.led_6_b, &RemoteXY.led_7_b, &RemoteXY.led_8_b, &RemoteXY.led_9_b, &RemoteXY.led_10_b, &RemoteXY.led_11_b, &RemoteXY.led_12_b};
int currentZone = 0; // current zone that is running
int singleZoneOn = -1; // single zones or zones started
loop:
// ADDED, A or M Switch Change////////////////////////////////////////////////////////////////////////////////////
if ((RemoteXY.auto_Run == 1) && (!autoON))
{
checkAorM();
}
if ((RemoteXY.manual_Run == 1) && (!manualON))
{
checkAorM();
}
if ((autoON) && (RemoteXY.auto_Run == 0))
{
checkAorM();
}
if ((manualON) && (RemoteXY.manual_Run == 0))
{
checkAorM();
}
if (autoON)
{
if (AorM == 1)
{
if (RemoteXY.start_Time_Hour == t.hour)
{
if (RemoteXY.start_Time_Minute == t.min)
{
checkWeekday();
if (((((((monDay) || (tueDay) || (wedDay) || (thuDay) || (friDay) || (satDay) || (sunDay)))))))
{
if (RemoteXY.season_Adj >= 1)
{
valvesShutDown();
AorM = 3;
autoON = true;
digitalWrite(PIN_AUTO_RUN, LOW); // GREEN
digitalWrite(AUTO_BLUE_PIN, HIGH); // BLUE
DebugPrintln("Auto Time to Start");
}
else
{
AorM = 2;
DebugPrintln("Skipping Autorun, Season Adjust Below 1");
}
}
}
}
}
}
// Reset AorM after Autorun Season Adjust Too Low
if ((AorM == 2) && ((RemoteXY.start_Time_Minute + 1) == t.min))
{
AorM = 1;
DebugPrintln("Autorun AorM Reset, Season Adjust Below 1");
}
if ((manualON) && (AorM == 1))
{
AorM = 3;
digitalWrite(PIN_MANUAL_RUN, HIGH); // RED
DebugPrintln("Manual Time to Start, Red LED ON");
}
if ((AorM >= 3) && (AorM < 8))
{
if (AorM == 3)
{
DebugPrintln("AorM = 3, Going to Start Pump");
AorMisRunning();
}
if (AorM == 4)
{
if ((millis() - z1Mill) >= pumpDelay)
{
AorM = 5;
DebugPrintln("AorM = 5, Pump Delay is Over");
AorMisRunning();
}
}
if (AorM == 6)
{
if (millis() - z1Mill >= xz1)
{
DebugPrintln("AorM = 6, Shutting Down and Switching Zones");
AorMisSwitching();
}
}
if (AorM == 7)
{
// if (currentZone == 1 || currentZone == 3 || currentZone == 5 || currentZone == 7)
//{
if ((millis() - z1Mill) >= linkedPumpDelay)
{
AorM = 5;
DebugPrintln("AorM = 7, Linked, Starting Second Zone");
AorMisRunning();
}
//}
}
}
// ADDED, A or M Switch Change////////////////////////////////////////////////////////////////////////////////////
// ADDED, Single Zone Switchs ////////////////////////////////////////////////////////////////////////////////////
if ((stateApp == 1) || (pumpRunning))
{
if ((AorM == 1) || (AorM == 16))
{
if (!manualON)
{
checkSingleZones();
}
}
}
if (singleZoneOn != -1)
{
if ((AorM == 8) || (AorM == 9))
{
if (zcrc == 0)
{
valvesShutDown();
AorM = 8;
}
singleZoneStarting();
}
if (AorM == 14)
{
if ((millis() - z1Mill) >= pumpDelay)
{
AorM = 15;
DebugPrintln("Single Zone, Pump Delay is Over");
singleZoneStarting();
}
}
if (AorM == 16)
{
if (millis() - z1Mill >= xz1)
{
DebugPrintln("Single Zones, Shutting Down Zones");
currentZone = 0;
singleZoneOn = -1;
AorM = 1;
valvesShutDown();
}
}
}
// ADDED, Single Zone Switchs ////////////////////////////////////////////////////////////////////////////////////
// ADDED, Checking A or M Switches//////////////////////////////////////////////////////////////////////////////
void checkAorM()
{
// If Auto was on and Auto Switch now off
if ((autoON) && (RemoteXY.auto_Run != 1))
{
valvesShutDown();
AorM = 1;
digitalWrite(PIN_AUTO_RUN, LOW); // GREEN
RemoteXY.auto_Run = 0;
DebugPrintln("Auto Was On and User Turned OFF, autoON Now is FALSE");
}
// If Manual was on and Manual Switch now off
if ((manualON) && (RemoteXY.manual_Run != 1))
{
valvesShutDown();
AorM = 1;
RemoteXY.manual_Run = 0;
DebugPrintln("Manual Was On and User Turned OFF, autoON Now is FALSE");
}
// Turn off Auto Green LED while Manual is Running
if ((autoON) && (RemoteXY.manual_Run == 1))
{
AorM = 1;
digitalWrite(PIN_AUTO_RUN, LOW); // GREEN
valvesShutDown();
manualON = true;
DebugPrintln("Override Auto to Manual, manualON Now is TRUE");
}
// Turn on Auto Green LED after Manual is done
if (((!manualON) && (AorM == 1) && (RemoteXY.auto_Run == 1)))
{
valvesShutDown();
digitalWrite(PIN_AUTO_RUN, HIGH); // GREEN
autoON = true;
DebugPrintln("Manual Cycle Done Or Just Turning Auto ON, autoON Now is TRUE");
}
// Turn on Manual
if ((!manualON) && (RemoteXY.manual_Run == 1))
{
valvesShutDown();
AorM = 1; // Should already be at 1???
manualON = true;
DebugPrintln("Manual Not ON, manualON Now is TRUE");
}
}
// ADDED, Checking A or M Switches//////////////////////////////////////////////////////////////////////////////
// ADDED, Auto or Manual is Running/////////////////////////////////////////////////////////////////////////////
void AorMisRunning()
{
if (sAdjust <= 0)
{
sprintf(RemoteXY.SA_text, "<-THIS TASK ONLY");
AorM = 1;
RemoteXY.manual_Run = 0;
valvesShutDown();
DebugPrintln("AorM Season Adjust Less Than 1, Now Ending");
}
if (!pumpRunning)
{
pumpStart();
currentZone = 0;
AorM = 4;
}
if (AorM == 5)
{
int zonePlusOne = currentZone + 1; // Add 1 for Pump is at Zero Index
digitalWrite(relays[zonePlusOne], LOW);
xz1 = *zoneRunTime[currentZone] * 60000;
// Check For Linked Zones
if (RemoteXY.linked_Valves == 1)
{
if (currentZone < 8)
{
// One Zone Already Started
if (zcrc >= 1)
{
AorM = 6;
}
// No Zones Started Yet
else
{
AorM = 7;
}
// if (currentZone == 1 || currentZone == 3 || currentZone == 5 || currentZone == 7)
if (AorM == 6)
{
int tempZoneRT = currentZone;
xz2 = *zoneRunTime[tempZoneRT] * 60000;
xz1 = max(xz1, xz2);
DebugPrintln("Linked Zone Run Time = ");
DebugPrint(xz1);
}
}
// Stopping Linking Zones After 7 and 8 Get Linked (Don't Link 9-12)
else
{
AorM = 6;
}
}
if (RemoteXY.linked_Valves == 0)
{
AorM = 6;
}
xz1 = round(xz1 * sAdjust);
zTime = xz1;
if (xz1 < 1)
{
pumpDelay = 0;
linkedPumpDelay = 0;
}
else
{
pumpDelay = tempPumpDelay;
linkedPumpDelay = tempLinkedPumpDelay;
}
DebugPrintln(sAdjust);
DebugPrintln(zTime);
*pumpORzone[currentZone] = 1;
z1Mill = millis();
zcrc++;
*pumpORzoneLED[currentZone] = 255;
DebugPrintln("Auto or Manual- Zone Started");
currentZone++;
// itoa(resetCounter, RemoteXY.rst_Times, 10); // MOVED HERE<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
itoa(currentZone, RemoteXY.rst_Times, 10); // MOVED HERE<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
}
}
// ADDED, Auto or Manual is Running/////////////////////////////////////////////////////////////////////////////
// ADDED, Auto or Manual is Shutting Down Zones/////////////////////////////////////////////////////////////////
void AorMisSwitching()
{
if (currentZone < 12)
{
if (zcrc > 1)
{
int zPlusOne = currentZone - 1; // Add 1 for Pump is at Zero Index
int tempZone = currentZone - 2;
digitalWrite(relays[zPlusOne], HIGH);
*pumpORzone[tempZone] = 0;
*pumpORzoneLED[tempZone] = 0;
DebugPrintln("Auto or Manual Linked Zones Shutting Down");
}
int tempZone2 = currentZone - 1;
digitalWrite(relays[currentZone], HIGH); // Add 1 for Pump is at Zero Index
*pumpORzone[tempZone2] = 0;
*pumpORzoneLED[tempZone2] = 0;
AorM = 4;
zcrc = 0;
z1Mill = millis();
DebugPrintln("Auto or Manual Zone Shutting Down");
}
else
{
if (RemoteXY.manual_Run != 0)
{
RemoteXY.manual_Run = 0;
}
AorM = 1;
valvesShutDown();
}
}
// ADDED, Auto or Manual is Shutting Down Zones/////////////////////////////////////////////////////////////////
// ADDED, Checking Single Zones for Control/////////////////////////////////////////////////////////////////////
void checkSingleZones()
{
if (zcrc == 1)
{
int szo = *pumpORzone[singleZoneOn];
if (szo == 0)
{
DebugPrintln("Single Zones, User Shut Down Zone");
currentZone = 0;
singleZoneOn = -1;
AorM = 1;
valvesShutDown();
}
}
if (zcrc == 2)
{
int czo = *pumpORzone[currentZone];
if (czo == 0)
{
DebugPrintln("Single Zones, User Shut Down Zone, Shutting Down Both");
currentZone = 0;
singleZoneOn = -1;
AorM = 1;
valvesShutDown();
}
}
if (zcrc < 2)
{
int z = 0;
while (z < 12)
{
uint8_t wz = *pumpORzone[z];
if (wz == 1)
{
if (singleZoneOn == -1)
{
currentZone = z;
singleZoneOn = z;
AorM = 8;
DebugPrintln("Single Zone, 1 Zone Set to Turn On");
break;
}
if (singleZoneOn != -1)
{
if (z != singleZoneOn)
{
currentZone = z;
AorM = 9;
DebugPrintln("Single Zone, 2nd Zone Set to Turn On");
break;
}
}
}
z++;
// Below Prints Constantly
// DebugPrintln("Single Zone, Zone Not On, Checking Next");
}
}
}
// ADDED, Checking Single Zones for Control/////////////////////////////////////////////////////////////////////
// ADDED, Single Zone Starting//////////////////////////////////////////////////////////////////////////////////
void singleZoneStarting()
{
if (sAdjust <= 0)
{
sprintf(RemoteXY.SA_text, "<-THIS TASK ONLY");
AorM = 1;
valvesShutDown();
DebugPrintln("Single Zone Season Adjust Less Than 1, Now Ending");
}
if ((AorM == 8) || (AorM == 9))
{
if (!pumpRunning)
{
pumpStart();
AorM = 14;
}
else
{
AorM = 14;
}
}
if (AorM == 15)
{
int zonePlusOne = currentZone + 1; // Add 1 for Pump is at Zero Index
digitalWrite(relays[zonePlusOne], LOW);
xz1 = *zoneRunTime[currentZone] * 60000;
xz1 = round(xz1 * sAdjust);
zTime = xz1;
if (xz1 < 1)
{
pumpDelay = 0;
linkedPumpDelay = 0;
}
else
{
pumpDelay = tempPumpDelay;
linkedPumpDelay = tempLinkedPumpDelay;
}
DebugPrintln(sAdjust);
DebugPrintln(zTime);
*pumpORzone[currentZone] = 1;
z1Mill = millis();
zcrc++;
AorM = 16;
*pumpORzoneLED[currentZone] = 255;
DebugPrintln("Single Zone- Zone Started");
// itoa(resetCounter, RemoteXY.rst_Times, 10); // MOVED HERE<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
itoa(currentZone, RemoteXY.rst_Times, 10); // MOVED HERE<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
}
}
// ADDED, Single Zone Starting////////////////////////////////////////////////////////////////////////////////