• Lets imagine that LED is not stuck and its functioning as needed. And LED is currently OFF during the time this check is done.

    In this case, you'd hope that the setInterval would do nothing at all, which I think is what happens? You don't want it to mess with pinMode if it's not needed because that might cause the pin to change state, setWatch would fire, and you'd register an invalid reading.

    In the case where the LED was on previously and then it turns off which I think is what you mean:

    pulledUp is actually false, so:

      if (!pulledUp) pinMode(D2,"input_pullup"); // this is called
      if (D2.read()) { // LED is off - this is called.
        onCount = 0;
        pulledUp = true;
      } else {
        // not called
      }
      if (!pulledUp) pinMode(D2,"input"); // pulledUp now true, so not called. pin mode is left as input_pullup
    }, 10000);
    
About

Avatar for Gordon @Gordon started