pinMode:
The pinMode() function is usually performed in the void setup() fragment of the code, and it serves the purpose of configuring the specified pin as either an INPUT or an OUTPUT.
A few important things to note about inputs and outputs:
Input pins:
Pins that source the data that is given to the microcontroller.
Arduino pins default to inputs, so you do not need to explicitly declare them as inputs in the setup (pins configured as such are said to be in a high-impedance state, which means that they have high opposition to the applied voltage). However, to avoid confusion, I generally label the pins that accept inputs from sensors, etc. as I have done in the fragment below.
In this code fragment, I first name pin 2 (on the microcontroller) 'sensorPin.' Then, in the setup, I use the pinMode function to assign the sensorPin as an input.
Output pins:
Pins through which the circuit performs operations that result from certain, given inputs.
Pins configured as outputs with the pinMode() function are said to be in a low-impedance state, meaning that they can apply a substantial amount of current to the circuit without much resistance, or impedance. This is why a pin connected to an LED would be considered an output pin.
To use the pinMode function, in the setup of your code, write pinMode(pin, mode), where mode refers to the designation of either INPUT, or OUTPUT.
Note: there is another designation of a pin known as input pullup, but if you’re a beginner, it is likely that it will not be used often in your initial sketches.
Comments