aboutsummaryrefslogtreecommitdiffstats
path: root/docs/source/arduino/loop.rst
diff options
context:
space:
mode:
Diffstat (limited to 'docs/source/arduino/loop.rst')
-rw-r--r--docs/source/arduino/loop.rst49
1 files changed, 26 insertions, 23 deletions
diff --git a/docs/source/arduino/loop.rst b/docs/source/arduino/loop.rst
index 165b7b0..b558edf 100644
--- a/docs/source/arduino/loop.rst
+++ b/docs/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() <arduino-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() <arduino-setup>`