Close

November 29, 2019

Using Functions in Arduino IDE

When you have a code that performs a specific task (for example, to play a series of notes),  you could put that code as a function. Whenever you need to play the song, you can just call that function instead of typing the code multiple times.

When you use functions, you make it easier to understand the flow of your program because the main section of the program is compact. 

In an Arduino sketch, you have two functions: setup() and loop(). Other functions must be created outside the brackets of those two functions.

Here’s an example of a function that simply runs the instructions contained. It doesn’t receive any input nor send any output back to the main program.

Functions can also receive input from the main program, makes a calculation, and send the output (results) back to the main program. Here’s an example.

Leave a Reply

Your email address will not be published. Required fields are marked *