bool

名称

bool

説明

boolはtrueもしくはfalseのどちらかの値を持つ。bool変数は1バイトの大きさである。

書式

bool var = val;

引数

var変数名。
val変数に代入する値。

使用例

以下のコードは、boolの使い方を示す。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
int LEDpin = 5;     // LED on pin 5
int switchPin = 13; // momentary switch on 13, other side connected to ground

bool running = false;

void setup() {
  pinMode(LEDpin, OUTPUT);
  pinMode(switchPin, INPUT);
  digitalWrite(switchPin, HIGH);  // turn on pullup resistor
}

void loop() {
  if (digitalRead(switchPin) == LOW) {
    // switch is pressed - pullup keeps pin high normally
    delay(100);                     // delay to debounce switch
    running = !running;             // toggle running variable
    digitalWrite(LEDpin, running);  // indicate via LED
  }
}

参照

言語 aref/constants_constants

オリジナルのページ

https://www.arduino.cc/reference/en/language/variables/data-types/bool/

Last Revision: 2019/07/19

最終更新日

January 4, 2024

inserted by FC2 system