Booleans

A boolean holds one of two values, true or false. On a Maple, each boolean variable has type bool.

Warning

On an Arduino, the type boolean is also provided. While the Maple also has this type for compatibility, its use is strongly discouraged. The bool type is a standard part of C++, while boolean is a non-standard extension that serves no purpose.

Example

// running is a boolean variable:
bool running = false;

void setup() {
    pinMode(BOARD_LED_PIN, OUTPUT);
    pinMode(BOARD_BUTTON_PIN, INPUT);
}

void loop() {
    if (isButtonPressed()) {
        // button is pressed
        running = !running;                     // toggle running variable
        digitalWrite(BOARD_LED_PIN, running)    // indicate via LED
    }
}

See Also

License and Attribution

Portions of this page were adapted from the Arduino Reference Documentation, which is released under a Creative Commons Attribution-ShareAlike 3.0 License.