Lesson-10-Basic-Arduino-Coding-Part-2
Lesson-10-Basic-Arduino-Coding-Part-2
ARDUINO
CODING
PART 2
RANDY B. SANFUEGO
Arduino Syntax and Program Flow
Syntax
void setup ( )
void loop ( )
Functions
The functions in Arduino combine many pieces of lines of code
into one.
The functions usually return a value after finishing execution.
But here, the function does not return any value due to the
presence of void.
The setup and loop function have void keyword present in front
of their function name.
The multiple lines of code that a function encapsulates are written inside
curly brackets.
Every closing curly bracket ' } ' must match the opening curly bracket '{ '
in the code.
We can also write our own functions, which will be discussed later in this
tutorial.
Spaces
Arduino ignores the white spaces and tabs before the coding statements.
The coding statements in the code are intent (empty spacing at the
starting) for the easy reading.
The verify icon present on the tool tab only compiles the code. It is a
quick method to check that whether the syntax of our program is correct
or not.
To compile, run, and upload the code to the board, we need to click on
the Upload button.
Uses of Parentheses ( )
It denotes the function like void setup ( ) and void loop ( ).
The parameter's inputs to the function are enclosed within the
parentheses.
It is also used to change the order of operations in mathematical
operations.
Semicolon ;
Program Flow
The program flow in Arduino is similar to the flowcharts. It represents the
execution of a program in order.
Flow Charts
A flowchart uses shapes and arrows to represent the information or
sequence of actions.
An oval ellipse shows the Start of the sequence, and a square shows the
action or processes that need to be performed.
The Arduino coding process in the form of the flowchart is shown below:
Here, the processor enters our code, and the execution of code begins.
After the setup, the execution of the statement in the loop begins.
The example of the flowchart in Arduino is shown below:
LAB ACTIVITY 4
LED with LDR
(October 09, 2024)