
{"id":3925,"date":"2018-06-05T08:04:31","date_gmt":"2018-06-05T08:04:31","guid":{"rendered":"http:\/\/dyor.roboticafacil.es\/?p=3925"},"modified":"2020-06-11T07:15:35","modified_gmt":"2020-06-11T07:15:35","slug":"instrucciones-para-el-control-de-flujo-en-facilino","status":"publish","type":"post","link":"https:\/\/dyor.webs.upv.es\/en\/instrucciones-para-el-control-de-flujo-en-facilino\/","title":{"rendered":"Control flow instructions in Facilino"},"content":{"rendered":"<p>In this post, we explain instructions related to the control flow of a program in Facilino.<\/p>\n<p><!--more--><\/p>\n<h3>What is the control flow?<\/h3>\n<p>In microcontrollers, the program flow, that how instructions are executed is usually sequential. This means that instructions are executed in order &#8220;as they appear&#8221;. In Facilino, &#8220;sequentially&#8221; is achieved by stacking blocks one after another one. Fortunately, we can modify the flow of a program by including instructions that will modify which is the next instruction to execute based on some conditions.<\/p>\n<p>Arduino has two main functions that must be included in every program to properly compile. The &#8220;setup&#8221; function allows you to include code that will be executed once at the beginning, while the &#8220;loop&#8221; function will allow you to execute code that will be endlessly repeated.<\/p>\n<p>Flow control can be achieved with loops that will allow us to repeat a set of instructions until a condition is met or conditional jump instructions that will determine wether a code will be executed or not.<\/p>\n<p>Within the flow control instructions, we can also find instructions related to delays that will simply wait until a given condition is met or a time has passed by before the next instruction is executed.<\/p>\n<h4>Setup\/Loop<\/h4>\n<p>Every Facilino program will include this instruction. The blocks included in the &#8220;Setup&#8221; container will be executed just once, while the block instructions included in the &#8220;Loop&#8221; container will be executed endlessly.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3934\" src=\"https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/06\/setup_loop.png\" alt=\"\" width=\"116\" height=\"99\" \/><\/p>\n<h4>Loops<\/h4>\n<p>Loops instructions in Facilino implement &#8220;while&#8221;, &#8220;for&#8221; and &#8220;do&#8230; while&#8221; instructions in Arduino. This type of instructions will allow you to execute a set of instructions (whatever we put inside the &#8220;do&#8221; container) until a condition is met. The difference between &#8220;while&#8221; and &#8220;do&#8230;while&#8221; is that instructions contained in a &#8220;while&#8221; block will be executed if the condition is met, while the instructions contained in a &#8220;do&#8230;while&#8221; block will be executed first and after that, the condition will be evaluated. A &#8220;for&#8221; block will iterate over a variable a given number of times to repeat a task.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3933\" src=\"https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/06\/do_while_for.png\" alt=\"\" width=\"298\" height=\"265\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Loops can be interrupted with a &#8220;break&#8221; instruction. Also, we might be interested in continuing with the loop by &#8220;jumping&#8221; the remainder of the \u001bcode of the iteration:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3935\" src=\"https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/06\/break_continue.png\" alt=\"\" width=\"310\" height=\"102\" srcset=\"https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/06\/break_continue.png 310w, https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/06\/break_continue-300x99.png 300w\" sizes=\"auto, (max-width: 310px) 100vw, 310px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h4>Conditional jumps<\/h4>\n<p>Conditional jump instructions in Facilino allow you to execute a code &#8220;if&#8221; a given condition is met. There are two types of blocks &#8220;if&#8221; and &#8220;switch&#8221;. The &#8220;if&#8221; block evaluates a binary expression and if it is true, then executes the code inside the container. Additional branches can be created by adding &#8220;else if&#8221; and &#8220;else&#8221; blocks in the mutator. A &#8220;switch&#8221; block instruction evaluates a number and depending on its value executes one case or another.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3937\" src=\"https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/06\/if_switch.png\" alt=\"\" width=\"145\" height=\"168\" \/><\/p>\n<h4>Delays<\/h4>\n<p>We can create simple delays of time (in milliseconds) or wait until a condition is met:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3938\" src=\"https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/06\/delays.png\" alt=\"\" width=\"306\" height=\"121\" srcset=\"https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/06\/delays.png 306w, https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/06\/delays-300x119.png 300w\" sizes=\"auto, (max-width: 306px) 100vw, 306px\" \/><\/p>\n<p>We can also meassure the current time from start in microseconds or milliseconds:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3939\" src=\"https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/06\/time_start.png\" alt=\"\" width=\"190\" height=\"92\" \/><\/p>\n<h5>Example 1<\/h5>\n<p>In this example we generate random numbers between 1 and 20. If the number is lower or equal than 15, then we show a message indicating that we must press a button switch (connected to pin D2) and generate another random number.<\/p>\n<p><iframe loading=\"lazy\" src=\"https:\/\/roboticafacil.es\/facilino\/blockly\/example.html?lang=en-GB&amp;proc=ArduinoNano&amp;example=control_flow_tutorial_example1.bly\" width=\"850\" height=\"320\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"yes\"><\/iframe><\/p>\n<h5>Example 2<\/h5>\n<p>In this example we generate ficticious temperatures between 5\u00baC and 40\u00baC randomly. Based on the temperature value, we show messages indicating that the temperatures is too high, too cold or simply perfect.<\/p>\n<p><iframe loading=\"lazy\" src=\"https:\/\/roboticafacil.es\/facilino\/blockly\/example.html?lang=en-GB&amp;proc=ArduinoNano&amp;example=control_flow_tutorial_example2.bly\" width=\"850\" height=\"600\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"yes\"><\/iframe><\/p>\n<h5>Example 3<\/h5>\n<p>In this example we show how to blink a LED 10 times.<\/p>\n<p><iframe loading=\"lazy\" src=\"https:\/\/roboticafacil.es\/facilino\/blockly\/example.html?lang=en-GB&amp;proc=ArduinoNano&amp;example=control_flow_tutorial_example3.bly\" width=\"550\" height=\"380\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"yes\"><\/iframe><\/p>","protected":false},"excerpt":{"rendered":"<p>Sorry, this entry is only available in Espa\u00f1ol.<\/p>\n","protected":false},"author":1,"featured_media":3926,"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-3925","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\/06\/control_flujo_bucles.png","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":3895,"url":"https:\/\/dyor.webs.upv.es\/en\/instrucciones-matriz-leds-facilino\/","url_meta":{"origin":3925,"position":0},"title":"Instructions for 8&#215;8 LEDs matrix in Facilino","author":"soporte","date":"Monday May 28th, 2018","format":false,"excerpt":"In this post, we explain the set of instructions available in Facilino to draw anything you want in 8x8 LEDs matrix. Available Instructions Facilino has a set of instructions to draw different patterns in an 8x8 LEDs matrix. All drawing instructions require the numbers of the CS, DIN and CLK\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\/05\/led_matrix_orientation_bb.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/05\/led_matrix_orientation_bb.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/05\/led_matrix_orientation_bb.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/05\/led_matrix_orientation_bb.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":1961,"url":"https:\/\/dyor.webs.upv.es\/en\/facilino-control\/","url_meta":{"origin":3925,"position":1},"title":"Tutorial 2: Manejo de bucles en Facilino","author":"soporte","date":"Tuesday May 30th, 2017","format":false,"excerpt":"Aprende a utilizar instrucciones de bucle en Facilino. En esta entrada se explica un sencillo ejemplo en el que el usuario introduce un valor a trav\u00e9s del Monitor de Facilino y Arduino realiza una operaci\u00f3n el n\u00famero de veces especificado (en este caso simplemente haremos parpadear el LED de Arduino).\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\/ejemplo2_11.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2017\/05\/ejemplo2_11.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2017\/05\/ejemplo2_11.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2017\/05\/ejemplo2_11.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":2054,"url":"https:\/\/dyor.webs.upv.es\/en\/guia-de-instalacion-de-facilino-en-windows\/","url_meta":{"origin":3925,"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":3916,"url":"https:\/\/dyor.webs.upv.es\/en\/instalacion-de-librerias-externas-de-facilino\/","url_meta":{"origin":3925,"position":3},"title":"External library installation in Facilino","author":"soporte","date":"Monday June  4th, 2018","format":false,"excerpt":"Some instructions in Facilino have a dependency on external libraries that must be added to Arduino IDE to compile the code. In this post, we explain the installation process of external libraries of Facilino. Facilino \u2194 Arduino IDE Arduino IDE comes with a set of libraries installed by default, that\u2026","rel":"","context":"In &quot;Facilino&quot;","block_context":{"text":"Facilino","link":"https:\/\/dyor.webs.upv.es\/en\/category\/programacion\/facilino\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/06\/arduino.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/06\/arduino.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/06\/arduino.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/06\/arduino.jpg?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":2066,"url":"https:\/\/dyor.webs.upv.es\/en\/guia-de-instalacion-de-facilino-en-ubuntu\/","url_meta":{"origin":3925,"position":4},"title":"Facilino Instalation Guide in Ubuntu (Linux)","author":"soporte","date":"Friday June 16th, 2017","format":false,"excerpt":"In this entry, we will describe download, instalation and license activation proces for Facilino in Ubuntu. Facilino is a free software, although it include a licence (a number) to activate advance features. In this entry, we will first show the process for downloading and installing Facilino. Download and Instalation You\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\/mi_cuenta.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2017\/06\/mi_cuenta.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2017\/06\/mi_cuenta.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2017\/06\/mi_cuenta.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2017\/06\/mi_cuenta.png?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":3430,"url":"https:\/\/dyor.webs.upv.es\/en\/lectura-de-una-entrada-digital-pulsador-en-facilino\/","url_meta":{"origin":3925,"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\/3925","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=3925"}],"version-history":[{"count":8,"href":"https:\/\/dyor.webs.upv.es\/en\/wp-json\/wp\/v2\/posts\/3925\/revisions"}],"predecessor-version":[{"id":5312,"href":"https:\/\/dyor.webs.upv.es\/en\/wp-json\/wp\/v2\/posts\/3925\/revisions\/5312"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dyor.webs.upv.es\/en\/wp-json\/wp\/v2\/media\/3926"}],"wp:attachment":[{"href":"https:\/\/dyor.webs.upv.es\/en\/wp-json\/wp\/v2\/media?parent=3925"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dyor.webs.upv.es\/en\/wp-json\/wp\/v2\/categories?post=3925"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dyor.webs.upv.es\/en\/wp-json\/wp\/v2\/tags?post=3925"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}