diff options
| author | Hanna Mendes Levitin <hanna@anomaly-3.local> | 2010-12-01 03:37:07 -0600 | 
|---|---|---|
| committer | Hanna Mendes Levitin <hanna@anomaly-3.local> | 2010-12-01 03:37:07 -0600 | 
| commit | 5a7dd1bea32458a4afc038984a903959134b82d3 (patch) | |
| tree | 4171e71c34841212585f855a3fbdf8aaf3b9bb4e /source/lang/cpp/booleanvariables.rst | |
| parent | 8e42d34c8d3c81c037a3acaca553ea8c5e4f25aa (diff) | |
| download | librambutan-5a7dd1bea32458a4afc038984a903959134b82d3.tar.gz librambutan-5a7dd1bea32458a4afc038984a903959134b82d3.zip | |
docs, now with style
Diffstat (limited to 'source/lang/cpp/booleanvariables.rst')
| -rw-r--r-- | source/lang/cpp/booleanvariables.rst | 54 | 
1 files changed, 54 insertions, 0 deletions
| diff --git a/source/lang/cpp/booleanvariables.rst b/source/lang/cpp/booleanvariables.rst new file mode 100644 index 0000000..6051b8c --- /dev/null +++ b/source/lang/cpp/booleanvariables.rst @@ -0,0 +1,54 @@ +.. 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 +------- + +:: + +    int ledPin = 13;      // LED on pin 13 +    int switchPin = 12;   // momentary switch on 12, other side connected to ground + +    // running is a boolean variable: +    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 +      } +    } + +See also +-------- + + +-  :ref:`Boolean constants <lang-constants-bool>` +-  :ref:`Boolean operators <lang-boolean>` +-  :ref:`Variables <lang-variables>` + + +.. include:: cc-attribution.txt | 
