> 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/digitalwrite.md).

# digitalWrite

## 函数原型

```cpp
void digitalWrite(uint8_t pin, uint8_t val);
```

## 作用

设置指定引脚的电位

{% hint style="info" %}
在调用此函数之前要保证该引脚已经 `pinMode` 过，且为输出模式。
{% endhint %}

## 参数

* `pin`

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

  引脚的电平。

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

| 值      | 名称  | 介绍        |
| ------ | --- | --------- |
| `HIGH` | 高电平 | 使引脚输出5V电压 |
| `LOW`  | 低电平 | 使引脚变为0V   |

## 示例

```cpp
digitalWrite(3, HIGH);  // 设置 3 号引脚为 高电平
digitalWrite(3, HIGH);  // 设置 3 号引脚为 低电平
```
