Loading...

Reference   Language | Libraries | Comparison | Changes

loop()

在setup()函数中初始化和定义了变量之后,loop()函数,顾名思义,不停的循环,根据程序中的内容,根据一些反馈,响应改变执行情况。我们就用loop中的代码控制Arduino板。

Example

 
int buttonPin = 3;

// setup中初始化串口和按键针脚. 
void setup()
{
  beginSerial(9600);
  pinMode(buttonPin, INPUT);
}

// loop中每次都检查按钮,如果按钮被按下,就发送信息到串口

void loop()
{
  if (digitalRead(buttonPin) == HIGH)
    serialWrite('H');
  else
    serialWrite('L');

  delay(1000);
}

Reference Home

Corrections, suggestions, and new documentation should be posted to the Forum.

The text of the Arduino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.