From 0dbb4829963a88a84a4387e8c9dc7ce94482a28b Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Wed, 25 May 2011 01:53:29 -0400 Subject: Docs: Move toggleLED() and waitForButtonPress() examples. These two examples from board-values.rst really belong in the documentation for the functions they reference. --- docs/source/lang/api/board-values.rst | 42 +++++++++-------------------- docs/source/lang/api/toggleled.rst | 22 ++++++++++++++- docs/source/lang/api/waitforbuttonpress.rst | 28 +++++++++++++++++-- 3 files changed, 60 insertions(+), 32 deletions(-) (limited to 'docs/source/lang/api') diff --git a/docs/source/lang/api/board-values.rst b/docs/source/lang/api/board-values.rst index 7198407..11b86a8 100644 --- a/docs/source/lang/api/board-values.rst +++ b/docs/source/lang/api/board-values.rst @@ -1,3 +1,5 @@ +.. highlight:: cpp + .. _lang-board-values: Board-Specific Values @@ -122,8 +124,9 @@ Constants default (i.e., they are in :ref:`boardUsedPins `). However, they can be used as ordinary GPIOs if you call the :ref:`lang-disabledebugports` - function. (Be careful with this on the Maple, as writing to - ``BOARD_NJTRST_PIN`` may cause your board to reset!). + function. (Be careful with this on the Maple and Maple RET6 + Edition, as writing to ``BOARD_NJTRST_PIN`` :ref:`may cause your + board to reset `\ !). .. _lang-board-values-pwm-pins: @@ -161,33 +164,14 @@ Examples :ref:`BOARD_LED_PIN ` On the Maple, the built-in LED is connected to pin 13. On the Maple Mini, however, it is connected to pin 33. You can write a "blinky" program that works -on all LeafLabs boards using ``BOARD_LED_PIN`` and :ref:`toggleLED() -`:: - - void setup() { - pinMode(BOARD_LED_PIN, OUTPUT); - } - - void loop() { - toggleLED(); - delay(100); - } - -:ref:`BOARD_BUTTON_PIN `: Similarly, you can -write a single program that prints a message whenever the button is -pressed which will work on all LeafLabs boards using -``BOARD_BUTTON_PIN`` and :ref:`isButtonPressed() -`:: - - void setup() { - pinMode(BOARD_BUTTON_PIN, INPUT); - } - - void loop() { - if (isButtonPressed()) { - SerialUSB.println("You pressed the button!"); - } - } +on both boards using :ref:`this example `. + +:ref:`BOARD_BUTTON_PIN `: On the Maple, the +built-in button is connected to pin 38. On the Maple Mini, however, +it is connected to pin 32. :ref:`This example +` shows how you can write a program +that prints a message whenever the button is pressed which will work +on all LeafLabs boards. See Also -------- diff --git a/docs/source/lang/api/toggleled.rst b/docs/source/lang/api/toggleled.rst index 54a7d64..cad347f 100644 --- a/docs/source/lang/api/toggleled.rst +++ b/docs/source/lang/api/toggleled.rst @@ -1,15 +1,35 @@ +.. highlight:: cpp + .. _lang-toggleled: toggleLED() =========== -Switches the LED from off to on, or on to off. +*Toggle* the built-in LED: switch it from off to on, or on to off. Library Documentation --------------------- .. doxygenfunction:: toggleLED +Example +------- + +.. _lang-toggleled-example: + +This example sets up the board's LED pin for output, then toggles the +LED every 100 milliseconds:: + + void setup() { + pinMode(BOARD_LED_PIN, OUTPUT); + } + + void loop() { + toggleLED(); + delay(100); + } + + See Also -------- diff --git a/docs/source/lang/api/waitforbuttonpress.rst b/docs/source/lang/api/waitforbuttonpress.rst index a5bd45c..0e0fbaf 100644 --- a/docs/source/lang/api/waitforbuttonpress.rst +++ b/docs/source/lang/api/waitforbuttonpress.rst @@ -1,16 +1,40 @@ +.. highlight:: cpp + .. _lang-waitforbuttonpress: waitForButtonPress() ==================== -Wait for the board's built-in button (labeled BUT on the silkscreen) -to be pressed, possibly with timeout. +Wait for the board's built-in button to be pressed, possibly with +timeout. The button is labeled "BUT" on the board's silkscreen. Its +pin number is the constant :ref:`BOARD_BUTTON_PIN +`. Library Documentation --------------------- .. doxygenfunction:: waitForButtonPress + +Example +------- + +.. _lang-waitforbuttonpress-example: + +This example sets up the board's button pin as an input, then prints a +message very time the button is pressed. + +:: + + void setup() { + pinMode(BOARD_BUTTON_PIN, INPUT); + } + + void loop() { + waitForButtonPress(); + SerialUSB.println("You pressed the button!"); + } + See Also -------- -- cgit v1.2.3