aboutsummaryrefslogtreecommitdiffstats
path: root/docs/source/arduino/loop.rst
blob: 165b7b01306bc65562df492811e902f274fa790a (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
.. _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.



Example
~~~~~~~

::

     
    int buttonPin = 3;
    
    // setup initializes serial and the button pin
    void setup()
    {
      beginSerial(9600);
      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');
    
      delay(1000);
    }