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

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://arduino.doc.skyone.host/core/io/digitalread.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
