1 Stored State with 1 Input Value for an Output

Hello,

I have an LED in a stored state (LED_state[0]), an LDR connected to A2.
I am trying to get it so that when the Checkbox is Checked and the LDR reading goes down to 500 the LED turns ON (When it goes to 600 it turns OFF).
But if the box is Unchecked it will not turn ON.

This is the base code:

if (StrContains(HTTP_req, "LED1=1")) {
        LED_state[0] = 1;  // save LED state
        digitalWrite(2, HIGH);
    }


cl.print("<LED>");
    if (LED_state[0]) {
        cl.print("checked");
    }
    else {
        cl.print("unchecked");
    }
    cl.println("</LED>");

I have tried all types of combinations including &&, || and even changing the values of the Analog input so it 'blocks'/give a NULL reading (To turn it 'OFF', was a 'swing-in-the-dark' hah).

If someone could Please help I would be Very Grateful :slight_smile:

I can't see anything in your code snippet that reads A2 or does anything with the results. It's never going to work without you writing some code so show us the best of your "all types of combinations" and we can start from there. And a complete program please so we can see how the variables etc. are set up.

Steve

Sorry I got it working, tried Another combination and it worked.
Not pretty coding but it does the job :slight_smile:

Thanks for replying though