loop()

名称

loop()

説明

初期化や変数の初期値を設定するためのsetup()関数を作成した後、loop()関数がその名の示す動作を正確に実行する。プログラムが何かに変更を加えたり反応したりを繰り返す。能動的にArduinoボードを制御するために利用する。

使用例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
int buttonPin = 3;

// setup initializes serial and the button pin
void setup() {
  Serial.begin(9600);
  pinMode(buttonPin, INPUT);
}

// loop checks the button pin each time,
// and will send serial if it is pressed
void loop() {
  if (digitalRead(buttonPin) == HIGH) {
    Serial.write('H');
  }
  else {
    Serial.write('L');
  }

  delay(1000);
}

参照

オリジナルのページ

https://www.arduino.cc/reference/en/language/structure/sketch/loop/

Last Revision: 2019/07/22

最終更新日

January 4, 2024

inserted by FC2 system