> For the complete documentation index, see [llms.txt](https://ubtechedu.gitbook.io/chinese/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ubtechedu.gitbook.io/chinese/arduino-language/structure/sketch/setup.md).

# setup()

在控制器中程序运行时将首先调用 setup() 函数。用于初始化变量、设置引脚的输出\输入类型、配置串口、引入类库文件等等。每次控制器上电或重启后，setup() 函数只运行一次。

### 例子 <a href="#shi-li" id="shi-li"></a>

```c
int buttonPin = 3; 
void setup(){  
    Serial.begin(9600);  
    pinMode(buttonPin, INPUT);
} 

void loop(){
  // ...
}
```
