# digitalRead

## 函数原型

```cpp
int digitalRead(uint8_t pin);
```

## 作用

读取指定引脚的电位

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

## 参数

* `pin`

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

## 返回值

* `int` 整型

  指定的引脚的电位

返回值有以下两种可能：

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

## 示例

```cpp
// 假设 4 号引脚连接的是 高电平
int state = digitalWrite(4);
// state = HIGH; 也就是 stats = 1;
```


---

# 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/digitalread.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.
