aboutsummaryrefslogtreecommitdiffstats
path: root/source/lang/cpp/booleanvariables.rst
blob: e032c74bd0dd5b074251ef9d5484bc1a9706c472 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
.. highlight:: cpp

.. _lang-booleanvariables:

Booleans
========

A **boolean** holds one of two values, :ref:`true
<lang-constants-true>` or :ref:`false <lang-constants-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
--------

-  :ref:`Boolean constants <lang-constants-bool>`
-  :ref:`Boolean operators <lang-boolean>`
-  :ref:`Variables <lang-variables>`

.. include:: /arduino-cc-attribution.txt