Configures the specified GPIO pin number as INPUT, OUTPUT or PWM pin.
pin - The GPIO pin number.
mode - Can be the followings:
INPUT : Sets pin as input without pullup resistor.
INTPUT_PULLUP : Sets pin as input with pullup resistor.
INTPUT_PULLDOWN : Sets pin as input with pulldown resistor.
OUTPUT : Sets pin as output.
SOFTPWM_OUTPUT : Same effect as OUTPUT. (Not available yet, still In progress).
PWM_OUTPUT : Sets pin as hardware PWM output. (Only for a few pins and requires sudo, see Notes below)
- pinMode function uses “/dev/gpiomem” as the default driver for GPIO and “/dev/mem” as the default driver for hardware PWM. If you want to change the GPIO driver to “/dev/mem”, for example, (which requires sudo) you can modify the GPIO_DRIVER_NAME constant as shown in the example. You can also change the default hardware PWM driver constant PWM_DRIVER_NAME the same way.
PWM_OUTPUT mode sets the pins as hardware PWM pins which uses the driver “/dev/mem” and which require root privilege (sudo).
These are the available pins for hardware PWM that is set when the mode PWM_OUTPUT is set. Only a few hardware PWM pins are exposed to the RPi connector/header and you can only use two PWM channels or pins maximum.
|GPIO PIN||Available in RPi (40-pins) connector||PWM channel|