Figure
2.1.14
: The interface and anatomy of the Arduino IDE.
Make sure that you disconnect the plug-ins of all the wires and pins the first
time you
power on the Arduino board either with a USB cable or a DC power port. It is a good
habit to never connect or disconnect any wires or pins when the board is power on.
Connect the Arduino UNO board and your PC or laptop using the USB cable. Under
“Tools” in the main menu (Figure 2.1.15) of the Arduino IDE, select the right board
from the drop-down menu of “Board:” and the right COM port from the drop-down
menu of “Port:” (which is the communication port the USB is using). Then disconnect
the USB cable from the Arduino UNO board.
Now let’s start coding in the Code Editor of the IDE.
An Arduino board runs with a
programming language called Processing, which is similar to C or C++ but much
Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js
How can we help you?
☰
simpler (
https://processing.org/
). We will not cover the details about the programming
syntax here; however, we will explain some of them along with the programming
structure and logic.
At the same time, you are encouraged to go to the websites of
Arduino and the Processing language to learn more details about the syntax of
Arduino programming.
Figure
2.1.15
: Select the right board and COM port in the Arduino IDE.
Arduino programs have a minimum of 2 blocks—a setup block and an execution loop
block. Each block has a set of statements enclosed in a pair of curly braces:
/*
Setup Block
*/
void setup() { //
Opening brace here
Statements 1; //
Semicolon after every
statement
Statements 2;
...
Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js
How can we help you?
☰
Statements n;
} //
Closing brace here
/*
Execution Loop Block
*/
void loop() { //
Opening brace here
Statements 1; //
Semicolon after every statement
Statements 2;
...
Statements n;
} //
Closing brace here
There must be a semicolon (;) after every statement to indicate the finish of a
statement; otherwise, the IDE will return an error during compiling. Statements after
“//” in a line or multiple lines of statements between the pair of “/*” and “*/” are
comments. Comments will not be compiled and executed,
but they are important to
help the readers understand the code.
Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js
How can we help you?
☰
Figure
2.1.16
: Program logic flowchart.
The program logic flowchart is shown in Figure 2.1.16. To better understand the code,
we will separate the code into a few parts according to the logic flowchart. Each part
will have its associated code shown in a grey box with explanations. You can copy and
paste them into the Code Editor in the Arduino IDE.
When writing the codes, be sure
to save them frequently.
Dostları ilə paylaş: