Reputation: 43
I'm learning embedded in school to program microcontrollers using C, i was wondering what the actual difference was between setting a pin on output vs input because i can't wrap my head around it, even though it sounds logical. I know I will be using the output register to send voltage to the pins but what will the input be used for then with an example? I guess it will be used to read output from the pins?
Upvotes: 2
Views: 1794
Reputation: 5510
The comments above show some more technical detail, this is a much simplified explanation which I hope will be more helpful to a beginner:
An input pin has a very high resistance. This means that something else can decide what voltage it has. The "something else" will be an output of some other device.
An output pin has a low resistance. This means that it decides what the voltage is*. That voltage can control something else.
Suppose you have a button and an LED light. The button gets connected to an input on your microcontroller, the software can read "in" whether the button is pressed or released, depending on the voltage that the switch connects to. Based on this, it can decide whether the LED should be on or off, and it then writes this "out" of an output pin, and the voltage there controls the LED.
*
assuming you don't create a short-circuit by connecting it to something driving a different voltage.
Upvotes: 4