pin going high not allowing analog read to change
The description you give for the desired behavior is very unclear and
hard to follow. I am going to rephrase what I think I understood in
terms of a finite state machine, which is the correct way of
describing this kind of systems. Please, review the description below,
as chances are I did not completely understand what you really want.

Let's say the system can be in any of these three states:


In the V_LOW state, the input voltage is below the threshold X and
the output is LOW. If the input raises above X, we set the output
to HIGH and transition to the V_HIGH state.
In the V_HIGH state, the input is above the threshold X and the
output is HIGH. If the input falls below X we go back to the
V_LOW state. If we remain in V_HIGH for three seconds, we switch
the output to LOW and go to the TIMEOUT state.
In the TIMEOUT state, the input is above the threshold, yet the
output is LOW. When the input falls below X we go to the V_LOW
state.


Below is a state graph for this machine. The states with a gray
background have the output LOW, whereas the state with a white
background has the output HIGH. Each possible transition is drawn as
an arrow, labeled by the condition that triggers the transition:



Is this the behavior you have in mind? If no, try to describe the
behavior you want in terms of a finite state machine, as I have done
here. If yes, then I suggest you follow chrisl's advice and implement
some hysteresis, by having different thresholds for going into and out
of V_LOW.

Anyhow, below is a translation of the FSM above in C++. It may not be
the most efficient way to write it, but I believe it is straightforward
enough to not require any additional explanation:

void update_output()
{
    static enum { V_LOW, V_HIGH, TIMEOUT } state;
    static uint32_t time_entered_v_high;
    int V = analogRead(A0);

    switch (state) {
    case V_LOW:
        if (V &gt;= X) {
            digitalWrite(pin, HIGH);
            state = V_HIGH;
            time_entered_v_high = millis();
        }
        break;
    case V_HIGH:
        if (V &lt; X) {
            digitalWrite(pin, LOW);
            state = V_LOW;
        } else if (millis() - time_entered_v_high &gt;= 3000) {
            digitalWrite(pin, LOW);
            state = TIMEOUT;
        }
        break;
    case TIMEOUT:
        if (V &lt; X) {
            state = V_LOW;
        }
        break;
    }
}




Edit 1: Here is how to implement the hysteresis: you need to choose a
second, lower threshold, for going back to the state V_LOW. Let's call
it Y, which is smaller than X. Then, both on the diagram and the
code, replace every instance of “V &lt; X” by “V &lt; Y”. That's it. There is
absolutely nothing more to change.



Edit 2: Addressing the updated question. Now the output should go
HIGH when the input is out of a defined range. I'll add hysteresis
right away by using four thresholds
V0&nbsp;&lt;&nbsp;V1&nbsp;&lt;&nbsp;V2&nbsp;&lt;&nbsp;V3:


the input is in range if it is within
[V1,&nbsp;V2)
the input is out of range if it is not within
[V0,&nbsp;V3)
the ranges [V0,&nbsp;V1)
and [V2,&nbsp;V3) provide hysteresis.


Note that for consistency I like to have all the intervals closed on the
same side. I will also rename the states V_LOW and V_HIGH to
IN_RANGE and OUT_OF_RANGE respectively. Here is the updated code:

void update_output()
{
    static enum { IN_RANGE, OUT_OF_RANGE, TIMEOUT } state;
    static uint32_t time_exited_range;
    int V = analogRead(A0);

    switch (state) {
    case IN_RANGE:
        if (V &lt; V0 || V &gt;= V3) {
            digitalWrite(pin, HIGH);
            state = OUT_OF_RANGE;
            time_exited_range = millis();
        }
        break;
    case OUT_OF_RANGE:
        if (V &gt;= V1 &amp;&amp; V &lt; V2) {
            digitalWrite(pin, LOW);
            state = IN_RANGE;
        } else if (millis() - time_exited_range &gt;= 3000) {
            digitalWrite(pin, LOW);
            state = TIMEOUT;
        }
        break;
    case TIMEOUT:
        if (V &gt;= V1 &amp;&amp; V &lt; V2) {
            state = IN_RANGE;
        }
        break;
    }
}