aboutsummaryrefslogtreecommitdiffstats
path: root/docs/source/lang/cpp
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@leaflabs.com>2011-06-10 09:10:03 -0400
committerMarti Bolivar <mbolivar@leaflabs.com>2011-06-10 09:10:03 -0400
commitdf044ee0c3a8602ac3329a86ff6c62d3ec4568b0 (patch)
tree100dcf093a7596c2632d4b944a46c5f3bd271a38 /docs/source/lang/cpp
parent7374b7e9e264cd231f1e2bba44e776533938d41a (diff)
downloadlibrambutan-df044ee0c3a8602ac3329a86ff6c62d3ec4568b0.tar.gz
librambutan-df044ee0c3a8602ac3329a86ff6c62d3ec4568b0.zip
Docs: Use "BOARD_LED_PIN" instead of "13".
Fix examples where pin 13 was used explicitly instead of BOARD_LED_PIN. Also change an AVR-specific example in docs/lang/cpp/booleanvariables.rst to Maple conventions.
Diffstat (limited to 'docs/source/lang/cpp')
-rw-r--r--docs/source/lang/cpp/bitwisemath.rst10
-rw-r--r--docs/source/lang/cpp/booleanvariables.rst19
-rw-r--r--docs/source/lang/cpp/define.rst6
-rw-r--r--docs/source/lang/cpp/if.rst14
-rw-r--r--docs/source/lang/cpp/int.rst4
-rw-r--r--docs/source/lang/cpp/unsignedint.rst4
6 files changed, 26 insertions, 31 deletions
diff --git a/docs/source/lang/cpp/bitwisemath.rst b/docs/source/lang/cpp/bitwisemath.rst
index 59794ba..cfe34f2 100644
--- a/docs/source/lang/cpp/bitwisemath.rst
+++ b/docs/source/lang/cpp/bitwisemath.rst
@@ -109,21 +109,21 @@ The ^ operator is often used to toggle (i.e. change from 0 to 1, or 1
to 0) some of the bits in an integer expression. In a bitwise OR
operation if there is a 1 in the mask bit, that bit is inverted; if
there is a 0, the bit is not inverted and stays the same. Below is a
-program to blink digital pin 13 (the LED pin on Maple)::
+program to toggle the built-in LED pin (you can also accomplish this
+with :ref:`lang-toggleled`)::
- // Blink Maple LED pin
+ // Toggle built-in LED pin
- int led_pin = 13;
int toggle = 0;
// demo for Exclusive OR
void setup(){
- pinMode(led_pin, OUTPUT);
+ pinMode(BOARD_LED_PIN, OUTPUT);
}
void loop(){
toggle = toggle ^ 1;
- digitalWrite(led_pin, toggle);
+ digitalWrite(BOARD_LED_PIN, toggle);
delay(100);
}
diff --git a/docs/source/lang/cpp/booleanvariables.rst b/docs/source/lang/cpp/booleanvariables.rst
index 0d76a12..e032c74 100644
--- a/docs/source/lang/cpp/booleanvariables.rst
+++ b/docs/source/lang/cpp/booleanvariables.rst
@@ -21,25 +21,20 @@ 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
+ pinMode(BOARD_LED_PIN, OUTPUT);
+ pinMode(BOARD_BUTTON_PIN, INPUT);
}
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
- }
+ if (isButtonPressed()) {
+ // button is pressed
+ running = !running; // toggle running variable
+ digitalWrite(BOARD_LED_PIN, running) // indicate via LED
+ }
}
See Also
diff --git a/docs/source/lang/cpp/define.rst b/docs/source/lang/cpp/define.rst
index bdf7283..b22085f 100644
--- a/docs/source/lang/cpp/define.rst
+++ b/docs/source/lang/cpp/define.rst
@@ -43,9 +43,9 @@ Example
::
- #define LED_PIN 13
- // The compiler will replace any mention of LED_PIN with
- // the value 3 at compile time.
+ #define MAPLE_LED_PIN 13
+ // The compiler will replace any mention of MAPLE_LED_PIN with
+ // the value 13 at compile time.
See Also
--------
diff --git a/docs/source/lang/cpp/if.rst b/docs/source/lang/cpp/if.rst
index d57b9f1..f248b05 100644
--- a/docs/source/lang/cpp/if.rst
+++ b/docs/source/lang/cpp/if.rst
@@ -43,28 +43,28 @@ conditional. If this is done, the next line (which ends in a
semicolon) becomes the only line in the body. The following three
``if`` statements all do the same thing::
- if (x > 120) digitalWrite(ledPin, HIGH);
+ if (x > 120) digitalWrite(pin, HIGH);
if (x > 120)
- digitalWrite(ledPin, HIGH);
+ digitalWrite(pin, HIGH);
if (x > 120) {
- digitalWrite(ledPin, HIGH);
+ digitalWrite(pin, HIGH);
}
However, the following two examples are different::
// example 1: two lines of code in the if body
if (x > 120) {
- digitalWrite(ledPin1, HIGH);
- digitalWrite(ledPin2, HIGH);
+ digitalWrite(pin1, HIGH);
+ digitalWrite(pin2, HIGH);
}
// example 2: one line of code in the if body, and
// another line of code after the if statement
if (x > 120)
- digitalWrite(ledPin1, HIGH); // this is in the if body
- digitalWrite(ledPin2, HIGH); // this is NOT in the if body
+ digitalWrite(pin1, HIGH); // this is in the if body
+ digitalWrite(pin2, HIGH); // this is NOT in the if body
In the first example, since the body is enclosed in curly braces, both
lines are included. In the second example, since the curly braces are
diff --git a/docs/source/lang/cpp/int.rst b/docs/source/lang/cpp/int.rst
index 3e96b69..fa63946 100644
--- a/docs/source/lang/cpp/int.rst
+++ b/docs/source/lang/cpp/int.rst
@@ -28,10 +28,10 @@ dealing with the :ref:`bitshift right operator (>>)
The ``long`` type is a synonym for ``int``.
-Here is an example of declaring an ``int`` variable named ``ledPin``,
+Here is an example of declaring an ``int`` variable named ``pin``,
then giving it value 13::
- int ledPin = 13;
+ int pin = 13;
The general syntax for declaring an ``int`` variable named ``var``,
then giving it value ``val``, looks like::
diff --git a/docs/source/lang/cpp/unsignedint.rst b/docs/source/lang/cpp/unsignedint.rst
index b7d9716..f8ea473 100644
--- a/docs/source/lang/cpp/unsignedint.rst
+++ b/docs/source/lang/cpp/unsignedint.rst
@@ -36,9 +36,9 @@ that an ``unsigned int`` will "underflow" at 0, and "overflow" at
The ``unsigned long`` type is a synonym for ``unsigned int``.
Here is an example of declaring an ``unsigned int`` variable named
-``ledPin``, then giving it value 13::
+``pin``, then giving it value 13::
- unsigned int ledPin = 13;
+ unsigned int pin = 13;
The general syntax for declaring an ``unsigned int`` variable named
``var``, then giving it value ``val``, looks like::