Book
Arduino programming
Arduino programming
Completion requirements
View
Blink a LED, the Arduino 'hello world'.
4. Deconstructing Blink
4.3. Functions
We will now take a step back, and look at the first line of code.
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
We see that the
pinMode
statement is included in a structure like this: void setup() {
...
}
These structures are called functions. In an Arduino sketch, these are the two basic sections: the setup() function and the loop() function.
void setup() {
...
}
void loop() {
...
}
Whatever is inside setup() happens once in the beginning of the program execution, followed by loop() which repeats over and over.