pinMode()
[Digital I/O]
void pinMode(unsigned short pin, unsigned short mode);
Description
Configures the specified pin to behave either as an input or an output.
It is possible to enable pull-up resistors with the mode
INPUT_PULLUP
. Additionally, alternative output modes are
available for all pins, such as THREE_STATE
,
OPEN_DRAIN
, and OPEN_COLLECTOR
.
Parameters
pin
: the Custom Element pin.
mode
: INPUT
, OUTPUT
,
INPUT_PULLUP
, THREE_STATE
,
OPEN_DRAIN
, or OPEN_COLLECTOR
Returns
Nothing.
Example Code
The code makes the digital pin 7 an OPEN_COLLECTOR
output and toggles it by alternating between HIGH and LOW at one second
pace.
void setup() {
(7, "OUT"); // sets the pin 7 label to "OUT"
pinLabel(7, OPEN_COLLECTOR); // sets the digital pin 7 as OPEN COLLECTOR output
pinMode}
void loop() {
// Remember that the pin is an OPEN COLLECTOR output,
// so it will only pull the voltage down
(7, HIGH); // sets the digital pin 7 to HIGH
digitalWrite(1000); // waits for a second
delay(7, LOW); // sets the digital pin 7 to LOW
digitalWrite(1000); // waits for a second
delay}
Notes and Warnings
All the pins can be used as digital pins, except for the power and ground pins.