aboutsummaryrefslogtreecommitdiffstats
path: root/source/lang/booleanvariables.rst
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@mit.edu>2010-11-28 11:23:33 -0500
committerMarti Bolivar <mbolivar@mit.edu>2010-11-28 11:23:33 -0500
commitd9cbd78e29d42e70bb46641dd43ee0772c8c975f (patch)
tree80a67cba4468dbcd89b3cd23ad56695b1f146c66 /source/lang/booleanvariables.rst
parent546b34076d230b617ba86defb6b90cd934b01878 (diff)
downloadlibrambutan-d9cbd78e29d42e70bb46641dd43ee0772c8c975f.tar.gz
librambutan-d9cbd78e29d42e70bb46641dd43ee0772c8c975f.zip
reorganized all the arduino/ docs into a lang/ subdirectory since
they're properly CC attributed now.
Diffstat (limited to 'source/lang/booleanvariables.rst')
-rw-r--r--source/lang/booleanvariables.rst55
1 files changed, 55 insertions, 0 deletions
diff --git a/source/lang/booleanvariables.rst b/source/lang/booleanvariables.rst
new file mode 100644
index 0000000..9d0e992
--- /dev/null
+++ b/source/lang/booleanvariables.rst
@@ -0,0 +1,55 @@
+.. 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 occupies one byte of memory, and 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