Robotics
Robotics
• Go to your classroom
• Select circuits
Deconstructing Arduino Code
// C++ code comment
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
digitalWrite(LED_BUILTIN, HIGH);
delay(1000); // Wait for 1000 millisecond(s)
digitalWrite(LED_BUILTIN, LOW);
delay(1000); // Wait for 1000 millisecond(s)
Functions
• We will now take a step back, and look at the first line of code.
void setup() {
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, there
are the two basic sections: the setup() function and the loop()
function.
• Whatever is inside setup() executes once
in the beginning of the program
execution,
Void setup()
outputs.
This is essentially the part of the program that describes blinking. We see that
blinking is actually turning a LED on, waiting for a while, turning it off, waiting for
a while again and then repeating from the top.
Let's take the statements one by one:
For the digital output pins of the Arduino, HIGH and LOW
means turning them ON and OFF.