Home » Programacion » Facilino » Facilino Tutorial » Tutorial 1: Adding up Two Numbers with Facilino

Tutorial 1: Adding up Two Numbers with Facilino

Learn how to use functions with return, join strings, some basic math operation and show results through the Facilino’s console. Example of summing up two numbers.

In this post, we will explain how functions work in Facilino through a simple example. We will show, step by step how to use a function with return to implement a simple procedure for summing up two numbers.

In ‘Functions’ category of Facilino, we can add a new instructions ‘function (with_return)’

Click on the empty field and write the name ‘sum’:

Now, click on the star and a window will be shown:

We can drag and drop ‘variable’ block within the parameters stack to create input arguments of the function. In this case, we would like to add two arguments with the names ‘x’ and ‘y’:

Now, we can click again on the star to close the window. Now, we can drag blocks within the function block. First we are going to show the input arguments and later we will show how to sum the numbers and show and return the result. We drag and drop the instruction to print on the serial console (inside the ‘Communications’ category):

Now, we would like to show the text ‘x=xxx‘, being xxx the value of the variable ‘x’ (input argument of the input). For that reason, we will use the block instruction ‘create text with’:

Concatenate this block instruction with the Serial print instruction and add a text block with “x=”, as shown:

Now, in order to use the actual value of the input argument we need to use the get variable instruction:

and select from the dropdown list the ‘x’ variable:

Concatenate this block to the second input of the ‘create text with’ block instruction:

Now, repeat the process with the variable ‘y’. We can save time by duplicating the already existing instruction:

Drag and drop the new block and modify the text and the variable:

Repeat this process again to show the result ‘z=x+y=xxx‘, being xxx the result of the sum. Disconnect the variable instruction so that we can delete it:

Drag and drop the variable instruction to the Trash bin to delete it:

Now, we will use the sum instruction from the ‘Math’ category:

and connect it to the second input of the last ‘create text with’ instruction:

Duplicate the variables and drop them inside the sum instruction:

And now, duplicate the sum instruction and connect it to the return of the function:

Once created, we can call the function in the ‘Functions’ category with the new function name:

To complete the example, we will create instructions to show an initial text at the beginning of the program:

Now, we are going to check if the sum is correct. Add an ‘if’ instruction in ‘Controls’ category:

and drop it just below the previous block:

To compare two number we will use the ‘equal to’ instruction:

as condition argument of the ‘if’ instruction:

Now, drag and drop the sum function into one of the ‘equal to’ inputs with the numbers ‘1’ and ‘2’:

And compare it with ‘3’:

Finally, show a message if the sum is correct or if it is wrong:

Here you can download Facilino’s code: