> For the complete documentation index, see [llms.txt](https://arduino.doc.skyone.host/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://arduino.doc.skyone.host/core/io/pinmode.md).

# pinMode

## 函数原型

```cpp
void pinMode(uint8_t pin, uint8_t mode);
```

## 作用

在使用引脚前，需要先使用 `pinMode()` 定义引脚的模式。

## 参数

* `pin`

  指定引脚的编号，如： `10` , `A0` 等。
* `mode`

  指定引脚的模式。

其中，`mode` 可以是以下值：

| 模式             | 名称     | 介绍                                                           |
| -------------- | ------ | ------------------------------------------------------------ |
| `INPUT`        | 输入模式   | 可以读取该引脚的电位                                                   |
| `OUTPUT`       | 输出模式   | 可以控制该引脚的输出                                                   |
| `INPUT_PULLUP` | 输入上拉模式 | 启动板载电阻，使该引脚可以直接连接 5V 电压而不需要在之间另加电阻，但**不能接负电位，不能接大于 5V 的电压。** |

## 示例

```cpp
pinMode(3, INPUT);          // 设置 3 号引脚为 输入模式
pinMode(4, OUTPUT);         // 设置 4 号引脚为 输出模式
pinMode(5, INPUT_PULLUP);   // 设置 5 号引脚为 输入上拉模式
```
