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() {
pinLabel(7, "OUT"); // sets the pin 7 label to "OUT"
pinMode(7, OPEN_COLLECTOR); // sets the digital pin 7 as OPEN COLLECTOR output
}
void loop() {
// Remember that the pin is an OPEN COLLECTOR output,
// so it will only pull the voltage down
digitalWrite(7, HIGH); // sets the digital pin 7 to HIGH
delay(1000); // waits for a second
digitalWrite(7, LOW); // sets the digital pin 7 to LOW
delay(1000); // waits for a second
}Notes and Warnings
All the pins can be used as digital pins, except for the power and ground pins.
