
{"id":3859,"date":"2018-05-24T08:22:27","date_gmt":"2018-05-24T08:22:27","guid":{"rendered":"http:\/\/dyor.roboticafacil.es\/?p=3859"},"modified":"2020-06-11T07:14:59","modified_gmt":"2020-06-11T07:14:59","slug":"funciones-facilino","status":"publish","type":"post","link":"https:\/\/dyor.webs.upv.es\/en\/funciones-facilino\/","title":{"rendered":"Functions and Procedures in Facilino"},"content":{"rendered":"<p>In this post, we explain the use of functions and procedures in Facilino.<\/p>\n<p><!--more--><\/p>\n<p>We can find the set of instructions related with functions and procedures within the &#8220;Functions&#8221; category in Facilino.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3860\" src=\"https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/05\/facilino_functions_instructions.png\" alt=\"\" width=\"257\" height=\"414\" srcset=\"https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/05\/facilino_functions_instructions.png 257w, https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/05\/facilino_functions_instructions-186x300.png 186w\" sizes=\"auto, (max-width: 257px) 100vw, 257px\" \/><\/p>\n<p>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.<\/p>\n<p>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 &#8220;mutator&#8221; icon (blue icon on top-left corner) and dragging as many variables as desired.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3862\" src=\"https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/05\/facilino_functions_input_args.png\" alt=\"\" width=\"516\" height=\"250\" srcset=\"https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/05\/facilino_functions_input_args.png 516w, https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/05\/facilino_functions_input_args-300x145.png 300w\" sizes=\"auto, (max-width: 516px) 100vw, 516px\" \/><\/p>\n<p>We must set a unique function name to avoid conflicts with other procedures or variables in the program.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3861\" src=\"https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/05\/facilino_functions_names.png\" alt=\"\" width=\"304\" height=\"200\" srcset=\"https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/05\/facilino_functions_names.png 304w, https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/05\/facilino_functions_names-300x197.png 300w, https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/05\/facilino_functions_names-75x50.png 75w\" sizes=\"auto, (max-width: 304px) 100vw, 304px\" \/><\/p>\n<p>Either, input arguments or the returned value can have different types:<\/p>\n<ul>\n<li>Integer: 16 bits integer number, corresponds to &#8220;int&#8221; type in Arduino.<\/li>\n<li>Long Integer: 32bits, integer number, corresponds to &#8220;long int&#8221; type in Arduino.<\/li>\n<li>Byte: 8bits integer number, corresponds to &#8220;byte&#8221; type in Arduino.<\/li>\n<li>Binary: Binario number, corresponds to &#8220;bool&#8221; type in Arduino.<\/li>\n<li>Float: Real number, corresponds to &#8220;float&#8221; type in Arduino.<\/li>\n<li>Text: Text string, corresponds to &#8220;String&#8221; type in Arduino.<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3863\" src=\"https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/05\/facilino_functions_input_type.png\" alt=\"\" width=\"519\" height=\"318\" srcset=\"https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/05\/facilino_functions_input_type.png 519w, https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/05\/facilino_functions_input_type-300x184.png 300w\" sizes=\"auto, (max-width: 519px) 100vw, 519px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3864\" src=\"https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/05\/facilino_functions_output_type.png\" alt=\"\" width=\"349\" height=\"249\" srcset=\"https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/05\/facilino_functions_output_type.png 349w, https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/05\/facilino_functions_output_type-300x214.png 300w\" sizes=\"auto, (max-width: 349px) 100vw, 349px\" \/><\/p>\n<p>In order to call a function or a procedure, we need to use the block instructions that will be created within the &#8220;Functions&#8221; 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, &#8220;func1&#8221; does not return any value and top-bottom connectors can be used to stack it anywhere. On the other hand, &#8220;func2&#8221; returns a value, which means that its output must be connected to any other input of compatible types.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3865\" src=\"https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/05\/facilino_functions_call.png\" alt=\"\" width=\"120\" height=\"171\" \/><\/p>\n<p>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.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3866\" src=\"https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/05\/facilino_functions_returns.png\" alt=\"\" width=\"196\" height=\"126\" \/><\/p>\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>Sorry, this entry is only available in Espa\u00f1ol.<\/p>\n","protected":false},"author":1,"featured_media":3865,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[97],"tags":[],"class_list":["post-3859","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-facilino-tutorial"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/05\/facilino_functions_call.png","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":1930,"url":"https:\/\/dyor.webs.upv.es\/en\/facilino-suma-numeros\/","url_meta":{"origin":3859,"position":0},"title":"Tutorial 1: Adding up Two Numbers with Facilino","author":"soporte","date":"Monday May 29th, 2017","format":false,"excerpt":"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\u2026","rel":"","context":"In &quot;Facilino Tutorial&quot;","block_context":{"text":"Facilino Tutorial","link":"https:\/\/dyor.webs.upv.es\/en\/category\/programacion\/facilino\/facilino-tutorial\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2017\/05\/func_with_return_setup_loop2.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2017\/05\/func_with_return_setup_loop2.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2017\/05\/func_with_return_setup_loop2.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":3412,"url":"https:\/\/dyor.webs.upv.es\/en\/lectura-de-un-potenciometro-en-facilino\/","url_meta":{"origin":3859,"position":1},"title":"Reading a Potentiometer with Facilino","author":"soporte","date":"Thursday April 26th, 2018","format":false,"excerpt":"In this post, we show a simple example for reading an analog input with Facilino. The analog input value is mapped into a value between 0 and 100 and this will control the integrated LED of Arduino Nano, based on its value. The aim of this example is to introduce\u2026","rel":"","context":"In &quot;Facilino Ejemplo&quot;","block_context":{"text":"Facilino Ejemplo","link":"https:\/\/dyor.webs.upv.es\/en\/category\/programacion\/facilino\/facilino-ejemplo\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/04\/pot_example_green.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":2054,"url":"https:\/\/dyor.webs.upv.es\/en\/guia-de-instalacion-de-facilino-en-windows\/","url_meta":{"origin":3859,"position":2},"title":"Gu\u00eda de Instalaci\u00f3n de Facilino en Windows","author":"soporte","date":"Friday June 16th, 2017","format":false,"excerpt":"En esta entrada se describir\u00e1 todo el proceso de descarga, instalaci\u00f3n y activaci\u00f3n de la licencia de Facilino en Windows. Facilino es un programa gratuito, si bien, incluye una licencia para activar las funcionalidades avanzadas. En esta entrada describiremos primero todo el proceso de descarga e instalaci\u00f3n de Facilino. Descarga\u2026","rel":"","context":"In &quot;Facilino Manual&quot;","block_context":{"text":"Facilino Manual","link":"https:\/\/dyor.webs.upv.es\/en\/category\/programacion\/facilino\/facilino-manual\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2017\/06\/Windows.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":2355,"url":"https:\/\/dyor.webs.upv.es\/en\/facilino-web\/","url_meta":{"origin":3859,"position":3},"title":"Facilino Web","author":"soporte","date":"Friday December 15th, 2017","format":false,"excerpt":"Introduction to Facilino Web multiplatform tool. Learn how to use basic features of Facilino (web) and how to program Arduino and ESP processors. Facilino web is a web page that allows you to generate code for Arduino, while the microcontroller programming must be actually carried out with Arduino IDE (Windows,\u2026","rel":"","context":"In &quot;Facilino Manual&quot;","block_context":{"text":"Facilino Manual","link":"https:\/\/dyor.webs.upv.es\/en\/category\/programacion\/facilino\/facilino-manual\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2017\/02\/Facilino_logo_vectorial.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2017\/02\/Facilino_logo_vectorial.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2017\/02\/Facilino_logo_vectorial.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2017\/02\/Facilino_logo_vectorial.jpg?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":3925,"url":"https:\/\/dyor.webs.upv.es\/en\/instrucciones-para-el-control-de-flujo-en-facilino\/","url_meta":{"origin":3859,"position":4},"title":"Control flow instructions in Facilino","author":"soporte","date":"Tuesday June  5th, 2018","format":false,"excerpt":"In this post, we explain instructions related to the control flow of a program in Facilino. What is the control flow? In microcontrollers, the program flow, that how instructions are executed is usually sequential. This means that instructions are executed in order \"as they appear\". In Facilino, \"sequentially\" is achieved\u2026","rel":"","context":"In &quot;Facilino Tutorial&quot;","block_context":{"text":"Facilino Tutorial","link":"https:\/\/dyor.webs.upv.es\/en\/category\/programacion\/facilino\/facilino-tutorial\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/06\/inicio_repetir.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":3430,"url":"https:\/\/dyor.webs.upv.es\/en\/lectura-de-una-entrada-digital-pulsador-en-facilino\/","url_meta":{"origin":3859,"position":5},"title":"Digital Input Read (Switch) with Facilino","author":"soporte","date":"Thursday April 26th, 2018","format":false,"excerpt":"In this post, we show how to read a digital input in Facilino. We show three examples using different instructions, but all of them produce the same result. The aim of this post is to show how to read a digital input in Facilino. Facilino has generic purpose instructions to\u2026","rel":"","context":"In &quot;Facilino Ejemplo&quot;","block_context":{"text":"Facilino Ejemplo","link":"https:\/\/dyor.webs.upv.es\/en\/category\/programacion\/facilino\/facilino-ejemplo\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/04\/switch_example_green.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/dyor.webs.upv.es\/en\/wp-json\/wp\/v2\/posts\/3859","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dyor.webs.upv.es\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dyor.webs.upv.es\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dyor.webs.upv.es\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dyor.webs.upv.es\/en\/wp-json\/wp\/v2\/comments?post=3859"}],"version-history":[{"count":7,"href":"https:\/\/dyor.webs.upv.es\/en\/wp-json\/wp\/v2\/posts\/3859\/revisions"}],"predecessor-version":[{"id":5310,"href":"https:\/\/dyor.webs.upv.es\/en\/wp-json\/wp\/v2\/posts\/3859\/revisions\/5310"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dyor.webs.upv.es\/en\/wp-json\/wp\/v2\/media\/3865"}],"wp:attachment":[{"href":"https:\/\/dyor.webs.upv.es\/en\/wp-json\/wp\/v2\/media?parent=3859"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dyor.webs.upv.es\/en\/wp-json\/wp\/v2\/categories?post=3859"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dyor.webs.upv.es\/en\/wp-json\/wp\/v2\/tags?post=3859"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}