diff options
Diffstat (limited to 'docs/source/lang/cpp/booleanvariables.rst')
-rw-r--r-- | docs/source/lang/cpp/booleanvariables.rst | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/docs/source/lang/cpp/booleanvariables.rst b/docs/source/lang/cpp/booleanvariables.rst new file mode 100644 index 0000000..e032c74 --- /dev/null +++ b/docs/source/lang/cpp/booleanvariables.rst @@ -0,0 +1,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 |