loop()
Description
After creating a
function, which initializes and sets the initial values, the setup()
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 Code
1int buttonPin = 3;2
3 // setup initializes serial and the button pin4 void setup() {5 Serial.begin(9600);6 pinMode(buttonPin, INPUT);7 }8
9 // loop checks the button pin each time,10 // and will send serial if it is pressed11 void loop() {12 if (digitalRead(buttonPin) == HIGH) {13 Serial.write('H');14 }15 else {16 Serial.write('L');17 }18
19 delay(1000);20 }
See also
Suggest changes
The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.
License
The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.