How it Works? (Software Setup)
The Blink sketch is the most basic sketch and is a great demonstration in learning the Arduino programming. It is the equivalent of the “Hello World!
” coding when people start their C or Java programming.
At the beginning of programming a code, developer or programmer usually will write some information about the code. You will see the block comment, or a multi-line comment is marked by the symbol /*
and the symbol */
marks its end. Arduino compiler reads the /*
, and it ignores whatever comes after that until it encounters a */
. You can use this whenever you want to add block comment in your code.
If you opt to write a one-line comment, you can use the symbol //
as per displayed in most code line in blink code example.
The next coding block is the void setup()
block which is executed only once when the Arduino starts up. It is used for commands that we only need to execute once. Here, we want to declare digital pin 13 as an output. However, notice that the code LED_BUILTIN
is used, where in this case, it means that we are initializing the built in LED that is internally connected with digital pin 13 as output. Consequently, we used digital pin 13 to be connected with external LED in this experiment. So, this is also correct.
Lastly, we have the third block of the sketch, the void loop()
that will be executed over and over until the power is cut off. In this sketch, we have two sets of digitalWrite()
and delay()
commands with different values as shown below:
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}