loop( )
在建置一个执行初始化与设定变数初始值的 setup( ) 函式之后,紧接会执行 loop( ) 函式。loop( ) 正如其名字所示,它会连续且重复的执行,让你的程式产生动作及回应;使用它来控制你的 86Duino 板动作。
范例
const int buttonPin = 3;
// 初始化 Serial 及设定按钮 pin 脚模式
void setup()
{
Serial.begin(9600);
pinMode(buttonPin, INPUT);
}
// 在每次执行 loop 时检查按钮 pin 脚的状态,
// 若按钮 pin 脚被按下则以 Serial 送出讯息。
void loop()
{
if (digitalRead(buttonPin) == HIGH)
Serial.write('H');
else
Serial.write('L');
delay(1000);
}
本页由热血青年 LBL 译自英文版。
The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.
