
{"id":142,"date":"2018-09-18T16:30:15","date_gmt":"2018-09-18T16:30:15","guid":{"rendered":"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/?page_id=142"},"modified":"2019-09-23T16:59:14","modified_gmt":"2019-09-23T16:59:14","slug":"topic-1-digital-output","status":"publish","type":"page","link":"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/microcontrollers\/mbed-os-2\/courses\/embedded-systems-in-context-level-4\/topic-1-digital-output\/","title":{"rendered":"Topic 1 &#8211; Digital Output"},"content":{"rendered":"<h1><b>Intended Learning Outcomes<\/b><\/h1>\n<ol>\n<li>Identify the leads of an LED and light via a current limiting resistor.<\/li>\n<li>Calculate the value of a current limiting resistor given an ideal current<\/li>\n<li>Use a DVM to measure potential difference in a circuit<\/li>\n<li>Apply Kirchoffs and Ohms laws to predict voltages and currents in a simple circuit<\/li>\n<li>Use the C language to drive a single GPIO pin to a given state<\/li>\n<\/ol>\n<p><strong>Time Required:\u00a0<\/strong>2 weeks (8 hours lab time + self-study).<\/p>\n<h1><b>Welcome<\/b><\/h1>\n<p>Welcome to the start of Embedded Systems in Context, a module focused on writing \u201cembedded software\u201d to measure, analyse and control real-world signals and information.<span class=\"Apple-converted-space\">\u00a0If you are a Plymouth student, then w<\/span>elcome also to the first semester on your taught programme.<\/p>\n<p>This module is a first introduction to the subject of electronics, robotics and software. The focus is on software, written to work in modern electronic systems.\u00a0Before we can even begin writing embedded software, it is important to have some understanding of fundamental electrical principles. Although this is taught elsewhere, it is helpful to cover the information on a needs-basis.<\/p>\n<hr \/>\n<h1><b>Activity 1.1<\/b><\/h1>\n<p>In electronics, we mostly work with one (or both) of the following signal types :<\/p>\n<ul>\n<li><a href=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/mbed-os-2\/courses\/glossary-2\/glossary\/\">Analogue<\/a> &#8211; where voltages and currents can take any value, typically between and upper and lower limit<\/li>\n<li><a href=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/mbed-os-2\/courses\/glossary-2\/digital-signal-glossary-entry\/\">Digital<\/a> &#8211; where signal voltages can only be one of two possible values<\/li>\n<\/ul>\n<p>For this section, the signals are all going to be digital. Let\u2019s start with a simple circuit diagram, or schematic as it\u2019s also known, as shown in<span class=\"Apple-converted-space\">\u00a0 <\/span>Figure 1.1<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-169 size-full\" src=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/SimpleLEDCircuit.png\" alt=\"\" width=\"537\" height=\"704\" srcset=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/SimpleLEDCircuit.png 537w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/SimpleLEDCircuit-229x300.png 229w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/SimpleLEDCircuit-260x341.png 260w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/SimpleLEDCircuit-160x210.png 160w\" sizes=\"auto, (max-width: 537px) 100vw, 537px\" \/><\/p>\n<p>There are three components in this circuit:<\/p>\n<ul>\n<li><a href=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/constant-voltage-source-glossary-item\/\"><b>Constant Voltage Source<\/b><\/a>. Think of this as the \u201cperfect battery\u201d. What ever the current I flowing in the circuit, the voltage across this device is ALWAYS Vout. In our circuit, this will be approximately 3.3V<\/li>\n<li><a href=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/mbed-os-2\/courses\/glossary-2\/resistor-glossary-entry\/\"><b>Resistor<\/b><\/a>. This is used to limit the current that flows through the LED (to avoid damaging it and to save power). Resistors have a resistance property measured in Ohms (symbol <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/ql-cache\/quicklatex.com-ec0c546b6596f336d8e1d41bb064b951_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#79;&#109;&#101;&#103;&#97;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"12\" style=\"vertical-align: 0px;\"\/>\u00a0).<\/li>\n<li><a href=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/mbed-os-2\/courses\/glossary-2\/led-light-emitting-diode-glossary-entry-tbd\/\" target=\"_blank\" rel=\"noopener\"><b>Light Emitting Diode<\/b><\/a> (LED) &#8211; A <b>non-linear<\/b> device that emits photons of light when a current passes through it.<span class=\"Apple-converted-space\">\u00a0<\/span>\n<ul>\n<li>Current can only flow in one direction<\/li>\n<li>Different LEDs have different characteristics.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2><b>Polarity of an LED<\/b><\/h2>\n<figure id=\"attachment_185\" aria-describedby=\"caption-attachment-185\" style=\"width: 181px\" class=\"wp-caption alignright\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-185\" src=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/LEDimage-181x300.png\" alt=\"\" width=\"181\" height=\"300\" srcset=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/LEDimage-181x300.png 181w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/LEDimage-260x431.png 260w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/LEDimage-160x265.png 160w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/LEDimage.png 285w\" sizes=\"auto, (max-width: 181px) 100vw, 181px\" \/><figcaption id=\"caption-attachment-185\" class=\"wp-caption-text\">Identifying the anode of the LED as the longer lead<\/figcaption><\/figure>\n<p>Unlike a resistor, it is important to get the LED the right way around.\u00a0<b>The current flows from anode to cathode. <\/b>Virtually no current will flow from cathode to anode.<\/p>\n<ul>\n<li>The <b>ANODE<\/b> is the <b>LONGER<\/b> leg on the LED.<span class=\"Apple-converted-space\">\u00a0<\/span><\/li>\n<li>For rounded body LEDs, a <b>flat section<\/b> on the body indicates the <b>cathode<\/b>.<\/li>\n<\/ul>\n<h2><b>Characteristics of an LED<\/b><\/h2>\n<p>In your kit, you are provided with three LEDs, red, green and amber. The data sheets for these devices are provided on the module site. However, the most important characteristics for a clear visible brightness are as follows:<\/p>\n<table style=\"border-collapse: collapse;border: 1px solid black\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"middle\"><\/td>\n<td valign=\"middle\"><b>current (approx.)<\/b><\/td>\n<td valign=\"middle\"><b>Voltage<\/b><\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\"><b>RED<\/b><\/td>\n<td valign=\"middle\">2mA<\/td>\n<td valign=\"middle\">1.7V<\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\"><b>AMBER<\/b><\/td>\n<td valign=\"middle\">2mA<\/td>\n<td valign=\"middle\">1.85V<\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\"><b>GREEN<\/b><\/td>\n<td valign=\"middle\">2mA<\/td>\n<td valign=\"middle\">1.9V<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>You can drive much higher currents through these LED\u2019s but the additional perceived brightness is not significant.<\/p>\n<p>We want to keep current LOW for two reasons:<\/p>\n<ul>\n<li>The source of power for the LED will be our microcontroller. From the <a href=\"http:\/\/www.st.com\/web\/en\/resource\/technical\/document\/datasheet\/DM00102166.pdf\">data sheet<\/a>, the maximum output current is limited to 25mA for a single pin, up to a total maximum of 120mA for all pins.<\/li>\n<li>We want to (and should) try to save power<\/li>\n<li>There will be tolerances around these values, and they do not need to be precise.<\/li>\n<\/ul>\n<p>Assume it is the green LED in the circuit:<\/p>\n<ul>\n<li class=\"mceTemp\">\n<figure id=\"attachment_187\" aria-describedby=\"caption-attachment-187\" style=\"width: 247px\" class=\"wp-caption alignright\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-187\" src=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/LEDcircuit-247x300.png\" alt=\"\" width=\"247\" height=\"300\" srcset=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/LEDcircuit-247x300.png 247w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/LEDcircuit-260x316.png 260w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/LEDcircuit-160x195.png 160w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/LEDcircuit.png 522w\" sizes=\"auto, (max-width: 247px) 100vw, 247px\" \/><figcaption id=\"caption-attachment-187\" class=\"wp-caption-text\">LED Circuit showing the current limiting resistor R.<\/figcaption><\/figure>\n<p>The voltage source <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/ql-cache\/quicklatex.com-3c491c4fe8e9fa63f9d3c1993c866991_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#86;&#95;&#123;&#111;&#117;&#116;&#125;&#61;&#51;&#46;&#51;&#86;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"91\" style=\"vertical-align: -3px;\"\/><span class=\"Apple-converted-space\">\u00a0<\/span><\/li>\n<li>We want <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/ql-cache\/quicklatex.com-082a60fa54f5ed5eb0f02e00b99ae5d2_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#73;&#61;&#50;&#109;&#65;&#61;&#48;&#46;&#48;&#48;&#50;&#65;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"148\" style=\"vertical-align: 0px;\"\/> to get a good brightness<\/li>\n<li>For this current, from the LED data sheet we expect <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/ql-cache\/quicklatex.com-1ca4a786b2672280f4d35e81dfc49282_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#86;&#95;&#123;&#76;&#69;&#68;&#125;&#61;&#49;&#46;&#57;&#86;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"104\" style=\"vertical-align: -3px;\"\/><\/li>\n<\/ul>\n<blockquote><p><span class=\"Apple-converted-space\">\u00a0<strong>Question:<\/strong> If <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/ql-cache\/quicklatex.com-23cd99e498dd9e466ef990197e1e1548_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#73;&#61;&#50;&#109;&#65;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"71\" style=\"vertical-align: 0px;\"\/>, show that the predicted value of <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/ql-cache\/quicklatex.com-2f5e2079de024587f5f8ae370392a707_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#86;&#95;&#82;&#61;&#49;&#46;&#52;&#86;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"82\" style=\"vertical-align: -3px;\"\/><\/span><\/p><\/blockquote>\n<p><span style=\"letter-spacing: 0.05em\">If you are unsure about how to answer this, check with the tutor.<\/span><\/p>\n<blockquote><p><span style=\"letter-spacing: 0.05em\"><strong>Question:<\/strong>\u00a0Given that <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/ql-cache\/quicklatex.com-7045af47a18d04340add4c959692a0c8_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#86;&#95;&#82;&#61;&#40;&#51;&#46;&#51;&#86;&#45;&#49;&#46;&#57;&#86;&#41;&#61;&#49;&#46;&#52;&#86;\" title=\"Rendered by QuickLaTeX.com\" height=\"19\" width=\"215\" style=\"vertical-align: -5px;\"\/>, and that the current <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/ql-cache\/quicklatex.com-23cd99e498dd9e466ef990197e1e1548_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#73;&#61;&#50;&#109;&#65;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"71\" style=\"vertical-align: 0px;\"\/>, what is the closest resister value <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/ql-cache\/quicklatex.com-dfd80738ac64385be5b381ea59d7fe55_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#82;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"14\" style=\"vertical-align: 0px;\"\/> available in the resistor draws in the lab?<\/span><\/p><\/blockquote>\n<h3><b>Theoretical Solution<\/b><\/h3>\n<p>From the previous section we calculated the resistor value as follows:<\/p>\n<p>According to Kirchoff\u2019s second law,<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/ql-cache\/quicklatex.com-c33918064195a00c835580eb071ae1d7_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#86;&#95;&#123;&#111;&#117;&#116;&#125;&#61;&#86;&#95;&#82;&#43;&#86;&#95;&#123;&#76;&#69;&#68;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"139\" style=\"vertical-align: -3px;\"\/><\/p>\n<p>&nbsp;<\/p>\n<p>Therefore, we calculate <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/ql-cache\/quicklatex.com-72c5a2411bc44a67fc2772b70c264f97_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#86;&#95;&#82;&#61;&#86;&#95;&#123;&#111;&#117;&#116;&#125;&#45;&#86;&#95;&#123;&#76;&#69;&#68;&#125;&#61;&#49;&#46;&#52;&#86;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"201\" style=\"vertical-align: -3px;\"\/><\/p>\n<p>Now we know what we <i>want<\/i> <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/ql-cache\/quicklatex.com-fdbb12e7e9c85bbbec70f51e7d85c5e4_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#86;&#95;&#82;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"21\" style=\"vertical-align: -3px;\"\/>\u00a0to be, we can calculate <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/ql-cache\/quicklatex.com-dfd80738ac64385be5b381ea59d7fe55_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#82;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"14\" style=\"vertical-align: 0px;\"\/> so that this condition is satisfied:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/ql-cache\/quicklatex.com-39b5a4e9e0d74bd4f82ef62be937b17e_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#86;&#95;&#82;&#61;&#73;&#32;&#92;&#99;&#100;&#111;&#116;&#32;&#82;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"81\" style=\"vertical-align: -3px;\"\/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/ql-cache\/quicklatex.com-e8274d21e1401fc333a64116511cd2e2_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#116;&#102;&#32;&#82;&#61;&#32;&#92;&#102;&#114;&#97;&#99;&#123;&#86;&#95;&#82;&#125;&#123;&#73;&#125;&#61;&#55;&#48;&#48;&#32;&#92;&#79;&#109;&#101;&#103;&#97;\" title=\"Rendered by QuickLaTeX.com\" height=\"23\" width=\"122\" style=\"vertical-align: -6px;\"\/><\/p>\n<p>However, from our resistor stock, we had <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/ql-cache\/quicklatex.com-591bcbda0d2859ddb61c5b5631204581_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#54;&#56;&#48;&#92;&#79;&#109;&#101;&#103;&#97;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"39\" style=\"vertical-align: 0px;\"\/>\u00a0resistors, so that was chosen as the nearest value.<\/p>\n<p>So let\u2019s now build this circuit and measure the actual voltages with a digital voltmeter (DVM).\u00a0The following shows how you wire up this circuit on a <a href=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/mbed-os-2\/courses\/glossary-2\/prototyping-board-glossary-entry\/\" target=\"_blank\" rel=\"noopener\"><b>prototyping board<\/b><\/a>.<\/p>\n<h1>Tasks<\/h1>\n<p>Connect your <a href=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/mbed-os-2\/courses\/glossary-2\/nucleo-board-glossary-entry\/\" target=\"_blank\" rel=\"noopener\"><b>Nucleo board<\/b><\/a> to the USB port of your PC, and the LED should light. We are using the 3.3V and ground (GND) pins on the Nucleo board to power this circuit.<\/p>\n<figure id=\"attachment_198\" aria-describedby=\"caption-attachment-198\" style=\"width: 871px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-198\" src=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/LightLEDCircuit.png\" alt=\"\" width=\"871\" height=\"873\" srcset=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/LightLEDCircuit.png 871w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/LightLEDCircuit-150x150.png 150w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/LightLEDCircuit-300x300.png 300w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/LightLEDCircuit-768x770.png 768w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/LightLEDCircuit-560x561.png 560w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/LightLEDCircuit-260x261.png 260w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/LightLEDCircuit-160x160.png 160w\" sizes=\"auto, (max-width: 871px) 100vw, 871px\" \/><figcaption id=\"caption-attachment-198\" class=\"wp-caption-text\">Connecting an LED to the 3.3V Power Supply of the Nucleo F429ZI board<\/figcaption><\/figure>\n<p>Follow this diagram carefully &#8211; note the polarity of the Digital Outputs and power lines. The resistor value is <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/ql-cache\/quicklatex.com-2a2ba8ad89448b4c4d46ba2ec301ec55_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#54;&#56;&#48;&#32;&#92;&#79;&#109;&#101;&#103;&#97;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"39\" style=\"vertical-align: 0px;\"\/>. Can you use your DVM to confirm which resistor has this value? <a href=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/mbed-os-2\/courses\/glossary-2\/resistor-glossary-entry\/\" target=\"_blank\" rel=\"noopener\">See the glossary item<\/a> for more ways to identify it. The choice of wire colour is more a convention than a rule. Please stick to this convention where possible to avoid errors.<\/p>\n<h2>Task 1.1.1<\/h2>\n<p>Watch the following video.<\/p>\n<p><iframe loading=\"lazy\" title=\"MBED - Video 1.0 Creating Power Rails\" width=\"750\" height=\"422\" src=\"https:\/\/www.youtube.com\/embed\/H4-NWoqm0BY?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/p>\n<table style=\"border-collapse: collapse;border: 1px solid black\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"middle\">We predicted the voltages across the resistor and LED to be 1.4V and 1.9V respectively.<span class=\"Apple-converted-space\">\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\">1. Now use a digital volt meter to confirm the actual values.<span class=\"Apple-converted-space\">\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\">2. Are they the same value as the person next to you?<\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\">3. Can you explain any differences?<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h2>Activity 1.2 &#8211; Blinky<\/h2>\n<p>When learning to program, there are one of two traditional programs you almost always write &#8211; here is the most popular in the embedded software world, \u201cblinky\u201d.<\/p>\n<p><iframe loading=\"lazy\" title=\"MBED - Video 1.1 Simple Blinky\" width=\"750\" height=\"422\" src=\"https:\/\/www.youtube.com\/embed\/GKV6NHeu4KM?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/p>\n<p>Before we write this software, first you build the circuit.<\/p>\n<ul>\n<li>The figure below is the schematic for the blinky circuit.<span class=\"Apple-converted-space\">\u00a0<\/span><\/li>\n<li>The prototype wiring is shown below.<\/li>\n<li>Watch the video &#8211;\u00a0<strong>Note<\/strong> we are using the FZ429ZI board now, and not the F401<\/li>\n<li>See the <a href=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/mbed-os-2\/courses\/glossary-2\/\" target=\"_blank\" rel=\"noopener\"><b>glossary<\/b><\/a> to identify the <a href=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/mbed-os-2\/courses\/glossary-2\/resistor-glossary-entry\/\" target=\"_blank\" rel=\"noopener\"><b>resistor<\/b><\/a> value.<\/li>\n<\/ul>\n<figure id=\"attachment_209\" aria-describedby=\"caption-attachment-209\" style=\"width: 418px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-209 size-full\" src=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/BlinkyCircuit.png\" alt=\"\" width=\"418\" height=\"464\" srcset=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/BlinkyCircuit.png 418w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/BlinkyCircuit-270x300.png 270w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/BlinkyCircuit-260x289.png 260w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/BlinkyCircuit-160x178.png 160w\" sizes=\"auto, (max-width: 418px) 100vw, 418px\" \/><figcaption id=\"caption-attachment-209\" class=\"wp-caption-text\">Schematic (Circuit Diagram) for the &#8220;Blinky&#8221; application.\u00a0<strong>Note<\/strong>: The microcontroller is not shown on this figure. Only the microcontroller pin D7 is shown to avoid clutter.<\/figcaption><\/figure>\n<p>The physical connections for this schematic are shown below. <em>Can you relate one to the other<\/em>?<\/p>\n<figure id=\"attachment_210\" aria-describedby=\"caption-attachment-210\" style=\"width: 800px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-210\" src=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/BlinkyConnections-1024x1024.png\" alt=\"\" width=\"800\" height=\"800\" srcset=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/BlinkyConnections-1024x1024.png 1024w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/BlinkyConnections-150x150.png 150w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/BlinkyConnections-300x300.png 300w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/BlinkyConnections-768x768.png 768w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/BlinkyConnections-560x560.png 560w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/BlinkyConnections-260x260.png 260w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/BlinkyConnections-160x160.png 160w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/BlinkyConnections.png 1814w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><figcaption id=\"caption-attachment-210\" class=\"wp-caption-text\">Physical Connections for the Blinky Circuit. TURN OFF power before building the circuit Double-check the 3.3V and GND (0V) is connected correctly. Connect D7 on the Nucleo board to the Anode (longer lead) of the LED. Connect the Cathode (shorter lead) of the LED to ground via a <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/ql-cache\/quicklatex.com-2a2ba8ad89448b4c4d46ba2ec301ec55_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#54;&#56;&#48;&#32;&#92;&#79;&#109;&#101;&#103;&#97;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"39\" style=\"vertical-align: 0px;\"\/> current limiting resistor<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<h3><b>Software<\/b><\/h3>\n<p>Below is the source code for blinky. Let\u2019s break this down line by line.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<pre class=\"theme:xcode lang:c++ mark:8 decode:true \">\/\/This is known as a \u201cheader file\u201d\r\n\/\/In short, this copies and pastes the text file\r\n\/\/mbed.h into this code\r\n#include \"mbed.h\"\r\n\r\n\/\/Create a DigitalOut \u201cobject\u201d called myled\r\n\/\/Pass constant D7 as a \u201cparameter\u201d\r\nDigitalOut myled(D7);\r\n\r\n\/\/The main function - all executable C \/ C++\r\n\/\/applications have a main function. This is\r\n\/\/out entry point in the software\r\nint main() {\r\n\r\n\/\/ ALL the code is contained in a \r\n\/\/ \u201cwhile loop\u201d\r\n    while(1) \r\n\t{\r\n\t\/\/The code between the { curly braces }\r\n\t\/\/is the code that is repeated\t\r\n        myled = 1; \/\/ External LED is ON\r\n        wait(1.0); \/\/ 1 second\r\n        myled = 0; \/\/ LED is OFF\r\n        wait(1.0); \/\/ External 1 second\r\n    }\r\n}<\/pre>\n<p>Firstly we have the DigitalOut \u201cobject\u201d named \u201cmyled\u201d (highlighted above). Think of this as a <i>component<\/i> you place in the software (as opposed to a circuit board). Some components have parameters you can use to initialize and customize them. We have one in this case.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-216 size-medium\" src=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/SoftwareComponentInstantiation-284x300.png\" alt=\"\" width=\"284\" height=\"300\" srcset=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/SoftwareComponentInstantiation-284x300.png 284w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/SoftwareComponentInstantiation-560x591.png 560w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/SoftwareComponentInstantiation-260x274.png 260w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/SoftwareComponentInstantiation-160x169.png 160w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/SoftwareComponentInstantiation.png 760w\" sizes=\"auto, (max-width: 284px) 100vw, 284px\" \/><\/p>\n<p>Components or \u201cobjects\u201d contain useful functionality. We are using a <strong>DigitalOut<\/strong> component to set a pin (D7) high or low. When we add an <b>instance<\/b> of this component to our application, we are also telling it which pin it is assigned to by passing a parameter.<\/p>\n<p>You can create more than one instance, but each instance must have a unique name so you can identify it.<\/p>\n<p>In our code, we say the object myled is of an instance of <b>type<\/b> DigitalOut<\/p>\n<p>One of the great things about components is that they hide the complex details inside, again very much like an electronic component. We just have to work with it\u2019s <b>interface<\/b>. This promotes reuse and shorter \/ easier to write code.<\/p>\n<p>Consider the following line. If we simply assign an integer value to an instance of DigitalOut, it knows to set the corresponding pin high (3.3V). This is possible because the component understands the \u2018=\u2019 operator to mean \u201cset the pin to this value\u201d.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-217\" src=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/AssignmentOperatorDigitalOut-258x300.png\" alt=\"\" width=\"258\" height=\"300\" srcset=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/AssignmentOperatorDigitalOut-258x300.png 258w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/AssignmentOperatorDigitalOut-768x893.png 768w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/AssignmentOperatorDigitalOut-560x651.png 560w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/AssignmentOperatorDigitalOut-260x302.png 260w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/AssignmentOperatorDigitalOut-160x186.png 160w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/AssignmentOperatorDigitalOut.png 793w\" sizes=\"auto, (max-width: 258px) 100vw, 258px\" \/><\/p>\n<p>Note the semi-colon ; on the end of the line.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-218\" src=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/main_function-300x246.png\" alt=\"\" width=\"300\" height=\"246\" srcset=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/main_function-300x246.png 300w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/main_function-768x630.png 768w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/main_function-560x460.png 560w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/main_function-260x213.png 260w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/main_function-160x131.png 160w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/main_function.png 860w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>Every executable C or C++ program has a function called main. For very simple programs, this is where you will write your code. For more complex programs you will probably break your task into separate functions.<\/p>\n<p>Note the code is written between the {curly parenthesis}. In embedded software, the main function rarely exits (it has nowhere to exit to!) unless you are running a multitasking operating system such as Linux.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-219\" src=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/CallingTheWaitFunction-274x300.png\" alt=\"\" width=\"274\" height=\"300\" srcset=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/CallingTheWaitFunction-274x300.png 274w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/CallingTheWaitFunction-768x842.png 768w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/CallingTheWaitFunction-560x614.png 560w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/CallingTheWaitFunction-260x285.png 260w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/CallingTheWaitFunction-160x175.png 160w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/CallingTheWaitFunction.png 841w\" sizes=\"auto, (max-width: 274px) 100vw, 274px\" \/><\/p>\n<p>In this line of code, we are invoking a function \u201cdelay\u201d. This simply delays execution for a specified time. This function is written for us (it is part of the Mbed library).\u00a0Delay has a single parameter. Note this time it is a fractional number.<\/p>\n<h2>TASK 1.2.1<\/h2>\n<table style=\"border-collapse: collapse;border: 1px solid black\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"middle\">Modify the software to do the following<\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\">1. Change the ON time to 5s and the OFF time to 2.5s<span class=\"Apple-converted-space\">\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\">2. Change the ON time to 1ms (0.001s) and the OFF time to 9ms<span class=\"Apple-converted-space\">\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\">3. What do you observe about the LED in (2)?<\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\">3. Modify the code to flash the morse-code SOS sequence (see opposite), wait for 5s, then repeat<\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\">In unsure, discuss with the tutor<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-221\" src=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/SOS-300x215.png\" alt=\"\" width=\"300\" height=\"215\" srcset=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/SOS-300x215.png 300w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/SOS-768x550.png 768w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/SOS-1024x734.png 1024w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/SOS-560x401.png 560w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/SOS-260x186.png 260w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/SOS-160x115.png 160w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2018\/09\/SOS.png 1104w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<table style=\"border-collapse: collapse;border: 1px solid black\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"middle\"><b>Symbol<\/b><\/td>\n<td valign=\"middle\"><b>Duration (milliseconds)<\/b><\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\">DOT<\/td>\n<td valign=\"middle\">150ms<\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\">Dash<\/td>\n<td valign=\"middle\">450ms<\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\">Symbol space<\/td>\n<td valign=\"middle\">1 dot<\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\">Letter Space<\/td>\n<td valign=\"middle\">3 dots<\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\">Word Space<\/td>\n<td valign=\"middle\">6 dots<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h2>Activity 1.3 &#8211; Hello World<\/h2>\n<p>The other tradition is Hello World. This is normally the first program you write when learning to program on a desktop computer. However, we\u2019re a generous lot, and wanted you to enjoy both &#8211; actually we have the luxury of being able to write both. Now watch the following video:<\/p>\n<p><iframe loading=\"lazy\" title=\"MBED - Video 1.2 - HelloWorld\" width=\"750\" height=\"563\" src=\"https:\/\/www.youtube.com\/embed\/MpMVj3xu3QM?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/p>\n<h2>TASK 1.3.1<\/h2>\n<table style=\"border-collapse: collapse;border: 1px solid black\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"middle\">Modify the software to write Hello World to the serial interface every 1s. Don\u2019t forget the new line character.<\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\">You should also use the Nucleo F429ZI board, and not the F401 as shown in the video.<\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\">Hint &#8211; write your code inside the while loop.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>See the glossary for a reminder about the <a href=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/while-loop-glossary-entry\/\"><b>while-loop<\/b><\/a>.<\/p>\n<pre class=\"theme:xcode lang:c++ decode:true\">#include \"mbed.h\"\r\n\r\n\/\/Create an instance of a Serial \r\n\/\/object called pc.\r\n\/\/Transmit and receive pins have pre-defined\r\n\/\/names USBTX and USBRX\r\nSerial pc(USBTX, USBRX);\r\n\r\nint main() \r\n{\r\n\r\n\/\/Set the baud rate property (bits per second)\r\n    pc.baud(9600);\r\n    \r\n    \/\/Call the printf method on pc\r\n    pc.printf(\"Hello World\\n\");\r\n\r\n    \/\/Run in an infinite loop\r\n    while(1) {\r\n    }\r\n}<\/pre>\n<h2>Task 1.3.2<\/h2>\n<table style=\"border-collapse: collapse;border: 1px solid black\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"middle\">Add two additional LED\u2019s to the breadboard. Don\u2019t forget to include the current limiting resistors.<\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\">Drive the three LEDs separately using D5, D6 and D7<\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\">Write some code to generate a timed traffic light sequence that repeats forever.<\/p>\n<p>RED, RED-AMBER, GREEN, AMBER<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>then repeat<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>ADDITIONAL Task 1.3.3<\/h2>\n<table style=\"border-collapse: collapse;border: 1px solid black\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"middle\">Modify the traffic light sequence as follows:<\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\">RED, RED-AMBER, GREEN, FLASHING-AMBER<\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\"><b>IF<\/b> you have some programming experience, try and break this into C functions. If you don\u2019t, we will cover this later in the course.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>ADDITIONAL (ADVANCED) Task 1.3.4<\/h2>\n<table style=\"border-collapse: collapse;border: 1px solid black\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"middle\">Modify your software to use a <code>BusOut<\/code> object instead of a <code>DigitalOut<\/code><\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\">See <a href=\"https:\/\/os.mbed.com\/docs\/v5.10\/apis\/busout.html\" target=\"_blank\" rel=\"noopener\">https:\/\/os.mbed.com\/docs\/v5.10\/apis\/busout.html<\/a>\u00a0for details<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Don\u2019t worry &#8211; we\u2019ve not covered <span class=\"lang:default decode:true crayon-inline \">BusOut<\/span>\u00a0 yet, but ultimately, it is important to be able to learn from the documentation.<\/p>\n<h2>ADDITIONAL (ADVANCED) TASK 1.3.5<\/h2>\n<p><em>ONLY for those with previous programming experience<\/em><\/p>\n<table style=\"border-collapse: collapse;border: 1px solid black\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"middle\">Modify your software to use a <code>Ticker<\/code> to perform the flashing.<\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\">See.<a href=\"https:\/\/os.mbed.com\/docs\/v5.10\/apis\/ticker.html\" target=\"_blank\" rel=\"noopener\">https:\/\/os.mbed.com\/docs\/v5.10\/apis\/ticker.html<\/a>\u00a0for details<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Again &#8211; don\u2019t worry if you can\u2019t do this- we will cover the <a href=\"https:\/\/os.mbed.com\/docs\/v5.10\/apis\/ticker.html\" target=\"_blank\" rel=\"noopener\">Ticker<\/a> later in the course. However, the documentation gives some nice examples you can adapt.<\/p>\n<h2>ADDITIONAL TASK 1.3.6<\/h2>\n<table style=\"border-collapse: collapse;border: 1px solid black\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"middle\">Build and test the code shown below. In the terminal, enter a name followed by a space then a number and press enter. Don&#8217;t worry if nothing appears on the screen as you type. The data is still being sent.<\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\">Can you explain what is happening? If not ask!<\/p>\n<p>Change the code to ask for two numbers which you then multiply and send the answer to the terminal.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>This uses the (in)famous <a href=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/mbed-os-2\/courses\/glossary-2\/scanf-glossary-entry\/\"><b>scanf<\/b><\/a> function. So many devices use string data to communicate that at some point, you will need to learn about it (it\u2019s introduced in this course).<\/p>\n<pre class=\"theme:xcode lang:c++ decode:true\">#include \"mbed.h\"\r\n\r\nSerial pc(SERIAL_TX, SERIAL_RX);\r\n\r\nint main() {\r\n    char nameString[30];\r\n    int age;\r\n    \r\n    pc.printf(\"Enter your first name, then a space, then your age\\n\\r\");\r\n    pc.scanf(\"%s %d\", nameString, &amp;age);\r\n    pc.printf(\"Hello %s\\n\\r\", nameString);\r\n    pc.printf(\"You are %d years old\\n\\r\", age);\r\n    \r\n    \/\/Loop forever\r\n    while(1);\r\n}<\/pre>\n<h2>ADDITIONAL TASK 1.3.7<\/h2>\n<table style=\"border-collapse: collapse;border: 1px solid black\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"middle\">The code below does the same as the previous example but the data input section has been moved to a separate <b>function<\/b>.<\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\">Modify the code to move the output section (the two <code>printf<\/code> statements) to another function.<\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\">Note the variables <code>nameStr<\/code> and <code>age<\/code> are now outside of all the functions. What happens if you put them inside main again?<span class=\"Apple-converted-space\">\u00a0<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre class=\"theme:xcode lang:c++ decode:true\">#include \"mbed.h\"\r\n\r\nSerial pc(SERIAL_TX, SERIAL_RX);\r\n\r\nchar nameStr[30]; \/\/ array of chars (string)\r\nint age;          \/\/ integer to hold your age\r\n\r\nvoid getData() \r\n{\r\n   pc.scanf(\"%s %d\", nameStr, &amp;age);\r\n}\r\n\r\nint main()\r\n{\r\n   getData();\r\n   \r\n   pc.printf(\"Hello %s \\n\\r\", nameStr);\r\n   pc.printf(\"You are %d \\n\", age);\r\n}<\/pre>\n<h2>ADDITIONAL TASK 1.3.8<\/h2>\n<p>(for those with coding experience)<\/p>\n<table style=\"border-collapse: collapse;border: 1px solid black\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"middle\">Build the code below and test<\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\">What happens if the line:<\/p>\n<p><code>int age = 1;<\/code><\/p>\n<p>is changed to<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p><code>int age;<\/code><\/td>\n<\/tr>\n<tr>\n<td valign=\"middle\">Modify the program such that:<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<ol>\n<li>When the while loop exits the last valid name and age entered are displayed.<span class=\"Apple-converted-space\">\u00a0<\/span><\/li>\n<li>Use a do &#8211; while loop instead of a while loop.<\/li>\n<li>Allow up to 10 names and ages to be entered and when the while loop exits print them out in the order they were entered.<span class=\"Apple-converted-space\">\u00a0<\/span><\/li>\n<li>Modify (4) to print out in reverse order with the average age.<\/li>\n<\/ol>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>See the glossary for more information on <a href=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/while-loop-glossary-entry\/\" target=\"_blank\" rel=\"noopener\"><b>while loops<\/b><\/a> and <a href=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/mbed-os-2\/courses\/glossary-2\/do-while-loop-glossary-entry\/\" target=\"_blank\" rel=\"noopener\"><b>do-while<\/b><\/a> loops<\/p>\n<pre class=\"theme:xcode lang:c++ decode:true\">#include \"mbed.h\"\r\n\r\nSerial pc(SERIAL_TX, SERIAL_RX);\r\n\r\nchar nameStr[30];           \r\nint age = 1;    \r\n            \r\nvoid getData()\r\n{\r\n   pc.scanf(\"%s %d\", nameStr, &amp;age);\r\n}\r\n\r\nvoid printData()\r\n{\r\n   pc.printf(\"Hello %s \\n\\r\", nameStr);\r\n   pc.printf(\"You are %d \\n\\r\", age);\r\n}\r\n\r\nint main()\r\n{\r\n   int counter = 0;\r\n   while (age &gt; 0)\r\n   {\r\n      getData();\r\n      printData();\r\n      counter++;\r\n   }\r\n   pc.printf(\"You entered %d names\\n\", counter);\r\n   sleep();\r\n}\r\n<\/pre>\n<h2>ADVANCED TASK 1.3.9<\/h2>\n<table style=\"border-collapse: collapse;border: 1px solid black\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"middle\">Read the keyboard input and translate into morse code.<\/p>\n<ul>\n<li>Echo the morse code using LED<\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h1>Setting the Pace<\/h1>\n<p>Ideally, you will have completed all the regular tasks (excluding those marked additional or advanced) by the end of the second week.<\/p>\n<hr \/>\n<h1>Feedback<\/h1>\n<p>If you wish to leave feedback or have a question, please use the form below.<\/p>\n<p>[contact-form][contact-field label=&#8221;Name&#8221; type=&#8221;name&#8221; required=&#8221;true&#8221; \/][contact-field label=&#8221;Email&#8221; type=&#8221;email&#8221; required=&#8221;true&#8221; \/][contact-field label=&#8221;Website&#8221; type=&#8221;url&#8221; \/][contact-field label=&#8221;Message&#8221; type=&#8221;textarea&#8221; \/][\/contact-form]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Intended Learning Outcomes Identify the leads of an LED and light via a current limiting resistor. Calculate the value of a current limiting resistor given an ideal current Use a DVM to measure potential difference in a circuit Apply Kirchoffs and Ohms laws to predict voltages and currents in a simple circuit Use the C&hellip; <a class=\"more-link\" href=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/microcontrollers\/mbed-os-2\/courses\/embedded-systems-in-context-level-4\/topic-1-digital-output\/\">Continue reading <span class=\"screen-reader-text\">Topic 1 &#8211; Digital Output<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":130,"menu_order":1,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-142","page","type-page","status-publish","hentry","entry"],"_links":{"self":[{"href":"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-json\/wp\/v2\/pages\/142","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-json\/wp\/v2\/comments?post=142"}],"version-history":[{"count":44,"href":"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-json\/wp\/v2\/pages\/142\/revisions"}],"predecessor-version":[{"id":717,"href":"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-json\/wp\/v2\/pages\/142\/revisions\/717"}],"up":[{"embeddable":true,"href":"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-json\/wp\/v2\/pages\/130"}],"wp:attachment":[{"href":"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-json\/wp\/v2\/media?parent=142"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}