top of page

Using Functions

As mentioned previously in this tutorial, everything that executes instructions in code is contained within functions.   Every piece of code written for an Arduino must contain the very important functions setup() and loop().  Functions can be used for a lot of other reasons as well, but possibly the most basic reason is to reduce code that is repeated.  

The following example shows how to call a function, the flow control when a function is called, and what line of code executes once the function has been completed and control returns to the loop() function-

At program start, the program jumps into the Setup(), as indicated by Step         Although, there is nothing in this example, normally whatever instructions are present will execute once.

The execution of code steps into the loop, where it will remain until reset or power is removed. This is shown in Step  

Step    shows a 'Function Call' to the 'PrintFunction()' function.

The next line that will be executed is step

bottom of page