最低限度

这是’最低限度’的 Arduino 草图。这可以通过选择 File > Examples > 01. Basics > Bare Minimum 加载到 Arduino IDE 中。

void setup() {
  // put your setup code here, to run once
}

void loop() {
  // put your main code here, to run repeatedly
}

程序启动时,setup() 函数中的代码将运行一次。这对于设置 I / O 引脚,初始化变量等很有用 .loop() 函数中的代码将重复运行,直到关闭 Arduino 或上传新程序。实际上,上面的代码在 Arduino 运行时库中看起来像这样:

setup();
while(1) {
  loop();
}

与你计算机上运行的程序不同,Arduino 代码永远不会退出。这是因为微控制器只有一个程序加载到其中。如果该程序退出,则无需告诉微控制器该做什么。