I think the fact that you have needed to write such a long explanatory post should cause you to pause and rethink. I confess I haven't read it all.
As far as I can see what you want to do is fairly simple and would be much easier to code if you think of it as states (a variable for each output) that are changed by a function that reads and assesses the "measured value". Then a separate function would switch on or off the outputs depending on the save state values.
Perhaps something like this pseudo code
outPinA = 8; // Arduino pin
outPinB = 9;
digOut2 = LOW; // low = off
digOut3 = LOW;
lowThresh = 200; // 20% of 1023
medThresh = 610; // 60% of 1023
hiThresh = 660; // 65% of 1023
void loop() {
measureInput();
controlOutput();
}
void (measureInput) {
valA = analogRead(pinA);
if (valA < lowThresh) {
digOut2 = LOW;
digOut3 = LOW;
// switch outputs
x = outPinA;
outPinA = outPinB;
outPinB = x;
}
if (valA > medThresh) {
digOut2 = HIGH;
}
if (valA > hiThres) {
digOut3 = HIGH;
}
}
void (controlOutput) {
digitalWrite(outPinA, digOut2);
digitalWrite(outPinB, digOut3);
}
...R