Introducing functions
A function is a piece of code defined by a name and that can be reused/executed from many different points in a C program. The name of a function has to be unique in a C program. It is also global
, which means, as you already read for variables, it can be used everywhere in the C program containing the function declaration/definition in its scope (see the The scope concept section in Chapter 3, C Basics – Making You Stronger).
A function can require special elements to be passed to it; these are called arguments. A function can also produce and return results.
Structure of a function
A function is a block of code that has a header and a body. In standard C, a function's declaration and definition are made separately. The declaration of the function is specifically called the declaration of the prototype of the function and has to be done in the header file (see Chapter 2, First Contact with C).
Creating function prototypes using the Arduino IDE
The Arduino IDE makes our...