Could somebody please explain the reason the following circuit works "fine" (LED is on if the button is pressed) only if the Pin 12 is in the OUTPUT-mode?
I need to be able to digitalRead() the button state (pressed/not pressed) and the LED should be on every time the button is pressed without using two pins (one input and one output).
I don't understand your thinking, but it is wrong. Try connecting the same black wire to ground instead of pin 12. Now it should work, and you can disconnect and sell the Arduino.
It's a funny comment for sure, but as I mentioned before I need to be able to read the state of the button and turn the LED on without using a second pin just for that.
So I'm trying to avoid using one input pin (for the button) and one output pin (for the LED) in this "standard" circuit:
You could budge something together with a mosfet or npn transistor to buffer the input to the pin. But why bother? In your code it doesn't really matter if 1 is 'pressed' or 0.
I'm trying to make a simple circuit with as few potential for things going wrong as possible for young students. For example it surely makes no difference for me, if it's 1 or 0, and I'm certainly able to get the value I want with code, but for a young student, trying to build his or hers first circuit, it's definitely not that simple.
I was looking for a way to use one pin less without additional parts or code, or understanding how the circuit works, but it seems to be impossible, so I should (and will) rather stick to the classic "one pin as input, one pin as output" example.
No, it doesn't, but it'll require additional electronics. So either the studens will have to understand what the inverting logic port of whatever implementation on their breadboard is for, or they have to wrap their head around the concept of "microcontroller sees high voltage when button is not pressed and vice versa". There is indeed no solution that's simpler on both fronts.
And now of course you'll still have to explain to them why the button-associated led isn't physically connected with the button...
I'm afraid you're not going to get out of explaining them something, one way or the other
Whether or not it is simple, it is important for any student not to imagine that there is a strict causal relationship between positive and negative, "high" and "low" - and "on" and "off".
Otherwise they will become - as some enquirers here have proven to be - terribly confused!
as some enquirers here have proven to be - terribly confused!
I'm quite sure that a "stupid" question is much better than no question at all, but thank you for the pointing out that I have a lot to learn about circuits! I surely do