# 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 号引脚为 低电平
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://arduino.doc.skyone.host/core/io/digitalwrite.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
