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/loop.rst | 49 ++++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 23 deletions(-) (limited to 'source/arduino/loop.rst') diff --git a/source/arduino/loop.rst b/source/arduino/loop.rst index 165b7b0..b558edf 100644 --- a/source/arduino/loop.rst +++ b/source/arduino/loop.rst @@ -1,39 +1,42 @@ +.. highlight:: cpp + .. _arduino-loop: loop() ====== -After creating a setup() function, which initializes and sets the -initial values, the loop() function does precisely what its name -suggests, and loops consecutively, allowing your program to change -and respond. Use it to actively control the Arduino board. - - +After creating a :ref:`setup() ` function, which +initializes your sketch, the ``loop()`` function gets called +repeatedly, allowing your program to change and respond. Use it to +actively control your Maple board. Example -~~~~~~~ +------- :: - - int buttonPin = 3; - + + int buttonPin = 38; + // setup initializes serial and the button pin - void setup() - { - beginSerial(9600); + void setup() { + SerialUSB.begin(); pinMode(buttonPin, INPUT); } - - // loop checks the button pin each time, - // and will send serial if it is pressed - void loop() - { - if (digitalRead(buttonPin) == HIGH) - serialWrite('H'); - else - serialWrite('L'); - + + // loop() checks the button pin each time it executes, + // and will print 'H' if it is pressed, 'L' otherwise + void loop() { + if (digitalRead(buttonPin) == HIGH) { + SerialUSB.println('H'); + } else { + SerialUSB.println('L'); + } + delay(1000); } +See Also +-------- + +- :ref:`setup() ` -- cgit v1.2.3