The void loop()
section is a function, the same as void setup()
is a function. When you start you Arduino program another function, that you can't see in the IDE, call setup()
and then calls loop()
repeatedly.
These other function you have seen, i.e. void Num_Write(int n)
can be called from either setup()
or loop()
and they will execute their instructions before returning to the function that called them. Its also possible the Num_Write()
may call other functions before it returns controller to the function that called it.
The type void
is used to represent nothing (its actually more complex than that, but for this level of explanation nothing will do). Other functions may return other types int
, char
, bool
for instance. So if we had a function like this:
int theMeaningOfLife(void)
{
return 42;
}
This is a function that returns an int
(a number) so you would call it like this:
void setup()
{
int number = theMeaningOfLife();
}
There is one catch, the function has to be declared BEFORE it is used, this allows the compiler to know what you are referring to. The simplest way of doing this is to write the function above the function that is calling it. The second way is to just write the function's signature above the function using it, i.e.:
int theMeaningOfLife(void);
void setup()
{
int number = theMeaningOfLife();
}
The best way (but not always practical on an Arduino) is to have all the function declarations in a header file (.h) and the code in a .cpp file. (Have a look a library to see what I mean).
Summary
There is only one function that is called repeatedly and that is the loop
function.
Just because a function returns void doesn't mean its going to loop repeatedly.