Skip to content

Commit

Permalink
en: dialogues-with-computer-program-structure: Expand the section
Browse files Browse the repository at this point in the history
* src/en/sections/dialogues-with-computer-program-structure.tex: Expand the
section.
  • Loading branch information
artyom-poptsov committed Feb 11, 2025
1 parent 7d27dc6 commit 6598a8d
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions src/en/sections/dialogues-with-computer-program-structure.tex
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,47 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{The program structure for Arduino}

A program that is written for an Arduino board usually consists of two basic
parts, also called \emph{functions}: \texttt{setup} and \texttt{loop}. An
example of a program that blinks an LED:
Our language for describing algorithms will be a general-purpose language called
C++. This is one of the popular programming language (at the time of writing of
this book) and it has a bunch of interesting applications. One of such
applications is the micro-controller programming.

A programming language provides for a programmer the basis for expressing ides,
while allows us to implement missing parts, thus expanding its toolkit. In our
case the integrated development environment for developing programs for Arduino
(called Arduino IDE) includes the set of required libraries that makes it easier
to develop programs for the platform.

Aside from that, to make our job easier, Arduino IDE generates a stub for our
code when we are creating an empty project. An Arduino program usually consists
of two basic parts, that also called \emph{functions}: \texttt{setup} and
\texttt{loop}. The stub looks like the following:

\begin{minted}{cpp}
void setup() {
// put your setup code here, to run once:
}

void loop() {
// put your main code here, to run repeatedly:
}
\end{minted}

The lines starting with double slash (``//'') are considered by computer as
commentaries and ignored. Usually we can add or remove those lines without
affecting the program logic, as the comments are for humans.

The \texttt{setup} procedure performs initialization of the micro-controller
when it starts. Here we should put all the commands that must be done once on
the system start.

The \texttt{loop} procedure executes after the finishing of \texttt{setup}
execution and automatically re-started by the system as soon as it finishes.
Thus, \texttt{loop} is enclosed in some kind of internal loop as the function
title suggest -- until the micro-controller is powered off.

In the previous subsection we formulated an algorithm for blinking one LED.
Let's try to implement the algorithm for Arduino.

\begin{minted}{cpp}
void setup() {
Expand Down

0 comments on commit 6598a8d

Please sign in to comment.