Home » Programacion » Facilino » Facilino Tutorial » Functions and Procedures in Facilino

Functions and Procedures in Facilino

In this post, we explain the use of functions and procedures in Facilino.

We can find the set of instructions related with functions and procedures within the “Functions” category in Facilino.

Functions and procedures will allow us to stack a set of instructions that you will be able to call later on at any place in your program. There are two types of functions, the ones with out return value and the ones that return a value. The first type, also known as procedures, are typically used to call a set of instructions, but they are not expected to return any value and will return to the execution point they where called after finishing. On the other side, functions are the ones that return a value, such that can be used when returning from the function after call in it.

In addition to this, functions (and procedures) can have multiple input arguments that will allow you to change the function behaviour based on its value. Typically, we can accept input arguments to do some computations that will be return as the return argument. We can also include Strings, numbers or any value that might affect the way we want the function to be executed. Input arguments can be added by simply clicking on the “mutator” icon (blue icon on top-left corner) and dragging as many variables as desired.

We must set a unique function name to avoid conflicts with other procedures or variables in the program.

Either, input arguments or the returned value can have different types:

  • Integer: 16 bits integer number, corresponds to “int” type in Arduino.
  • Long Integer: 32bits, integer number, corresponds to “long int” type in Arduino.
  • Byte: 8bits integer number, corresponds to “byte” type in Arduino.
  • Binary: Binario number, corresponds to “bool” type in Arduino.
  • Float: Real number, corresponds to “float” type in Arduino.
  • Text: Text string, corresponds to “String” type in Arduino.

In order to call a function or a procedure, we need to use the block instructions that will be created within the “Functions” category in Facilino. With the dropdown list we can select the function we are interested in. The input arguments of each call will be modified based on the selected function name, so if you change it, all block instructions connected to those inputs, will be disconnected. Based on the previous example, we show the two block instructions that your should have. As you can see, “func1” does not return any value and top-bottom connectors can be used to stack it anywhere. On the other hand, “func2” returns a value, which means that its output must be connected to any other input of compatible types.

In addition to this, functions that return a value have a pair of instructions that might be of interest too. They are used to return a value without the need of reaching the end of the function. In particular, on of the block instructions returns a value conditionally, meaning that only returns the value if a condition is met and the other always returns a value in this block instruction is executed.