# analogRead

## 函数原型

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

## 作用

读取指定引脚的电位，**只有支持模拟输入的引脚才能调用此函数。**

**注意：** 在调用此函数之前要保证该引脚已经 `pinMode` 过，且为输入模式。

## 参数

* `pin`

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

## 返回值

* `int` 整型

  指定的引脚的电位

返回值的范围为 **0\~1023**

## 示例

```cpp
// 假设 4 号引脚连接的是 3V
int state = digitalWrite(4);
// state = 3 * 1023 / 5;
```


---

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