Newbie here (first post) and excited to be part of this lively community.
I’ve noticed a strange behaviour with my Spark Core. I can perform a digitalWrite to it to turn on the “D” pins but when I try to read the values, it toggles from HIGH to LOW.
Does anyone have any idea what may be wrong? Many thanks in advance.
It might have something to do with the fact that you’ve configured that pin to be an output, and you’re now using it as an input. I’m guessing it has to initialize again, thus setting the pin low.
I’m not sure of the above, so let’s wait for some more experienced folks to join in
While @Moors7 is right that you have to configure the pin as INPUT to read any external signal, I’d like to add that you then actually have to provide some external circuitry to produce this signal. Otherwise you’re measuring a floating input.
One way to do this internally would be to use INPUT_PULLUP or INPUT_PULLDOWN instead.
But even if you set your pinMode(Dx, OUTPUT) you can still digitalRead() that pin, but you don’t actually “measure” the pins state, but only get back the state of the respective bit in the output register of the µC port being “home” of that pin.