Mixly Block Category - Functions
Segmenting code into functions allows a programmer to create modular pieces of code that perform a defined task and then return to the area of code from which the function was "called". The typical case for creating a function is when one needs to perform the same action multiple times in a program.
Read more here: https://www.arduino.cc/en/Reference/FunctionDeclaration
Contents
Create a Procedure/Function
Functions can take in Variables. These variables are passed to the functions and used by the function. These variables are known as parameters or inputs. Functions can be created with a return, which means the Function will return a value after execution is complete.
Configuring Input
Input variables can be passed to Functions / Procedures which can be used in the encapsulated set of blocks. To configure how many Input Variables there are. Simply click on the gear icon and drag the amount of variables and define the type for each.
Without Return
This block encapsulates a set of blocks that execute. There is no return, which means no value is returned after the function is done.
- Function / Procedure Name - Give a name to the function / procedure. Used to reference when calling the function / procedure.
With Return
This block encapsulates a set of blocks that execute. There is return, which means a value is returned after the function is done.
If ... then ... return
This block is used to check a condition and if true will return immediately (exit the function).
- Condition - Variable or statement that evaluates to a bool. If true, a return occurs, which exits the function. If false, then skip to the next block.
After Creating a Procedure/Function
After creating a Function / Procedure a new block is added to the category which allows calling the Function / Procedure.
Call a Procedure/Function
This blocks called the Function / Procedure as defined.