aboutsummaryrefslogtreecommitdiffstats
path: root/source/arduino/loop.rst
blob: 4383ab6d89c79260fb103c6aa6bc035ff8e9cabb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
.. highlight:: cpp

.. _arduino-loop:

loop()
======

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 = 38;

    // setup initializes serial and the button pin
    void setup() {
      SerialUSB.begin();
      pinMode(buttonPin, INPUT);
    }

    // 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>`


.. include:: cc-attribution.txt