From 2d429e75ce69e77f8c95490ac03881ec9aa0354a Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Mon, 25 Oct 2010 21:15:28 -0400 Subject: arduino language reference nearing completion, properly CC-BY-SA 3.0 attributed --- source/arduino/booleanvariables.rst | 59 ++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 30 deletions(-) (limited to 'source/arduino/booleanvariables.rst') diff --git a/source/arduino/booleanvariables.rst b/source/arduino/booleanvariables.rst index 3bbe72a..772db0f 100644 --- a/source/arduino/booleanvariables.rst +++ b/source/arduino/booleanvariables.rst @@ -1,53 +1,52 @@ +.. highlight:: cpp + .. _arduino-booleanvariables: -boolean -======= +Booleans +======== -A **boolean** holds one of two values, -`true `_ or -`false `_. (Each boolean -variable occupies one byte of memory.) +A **boolean** holds one of two values, :ref:`true +` or :ref:`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 = 5; // LED on pin 5 - int switchPin = 13; // momentary switch on 13, other side connected to ground - - boolean running = false; - - void setup() - { - pinMode(LEDpin, OUTPUT); + 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 + + 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 + digitalWrite(ledPin, running) // indicate via LED } } - - - - - See also -------- -- `constants `_ -- `boolean operators `_ -- `Variable Declaration `_ - - +- :ref:`Boolean constants ` +- :ref:`Boolean operators ` +- :ref:`Variables ` -- cgit v1.2.3