
{"id":764,"date":"2019-09-27T07:11:33","date_gmt":"2019-09-27T07:11:33","guid":{"rendered":"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/?page_id=764"},"modified":"2019-10-10T09:04:48","modified_gmt":"2019-10-10T09:04:48","slug":"managing-multiple-inputs-and-outputs","status":"publish","type":"page","link":"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/microcontrollers\/mbed-os-2\/courses\/level-5-embedded-and-real-time-systems\/managing-multiple-inputs-and-outputs\/","title":{"rendered":"Managing Multiple Inputs and Outputs"},"content":{"rendered":"<p><a href=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/microcontrollers\/mbed-os-2\/courses\/level-5-embedded-and-real-time-systems\/\">Table of Contents<\/a><\/p>\n<hr \/>\n<p>In this section, we will look at digital inputs, and how we might use them to control digital outputs.<br \/>\nWe will be using a simple \u201cpush-to-make switch\u201d to generate a single digital bit of data.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-765\" src=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/spst.png\" alt=\"\" width=\"85\" height=\"93\" \/><\/p>\n<h2>Activity 3.1 &#8211; Simple Switch Input<\/h2>\n<p>Remember that a single digital signal is either ON or OFF. Numerically, we represent this as 1 or 0 (a single binary digit). The simplest way to generate a single bit input signal is with a push switch (shown below). The schematic to generate a digital input is as follows.<\/p>\n<figure id=\"attachment_766\" aria-describedby=\"caption-attachment-766\" style=\"width: 201px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-766\" src=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/Activity-3-1.png\" alt=\"\" width=\"201\" height=\"280\" \/><figcaption id=\"caption-attachment-766\" class=\"wp-caption-text\">Using a SPST switch as a digital input<\/figcaption><\/figure>\n<p>Wire up this circuit on your prototype board.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-769 size-medium\" src=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/reminder-platform-300x157.png\" alt=\"\" width=\"300\" height=\"157\" srcset=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/reminder-platform-300x157.png 300w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/reminder-platform-768x401.png 768w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/reminder-platform.png 778w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<h2>Activity 3.2 &#8211; Reading Digital Inputs<\/h2>\n<p>Wire up 3 LED\u2019s as shown here. These will be used for outputs.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-770\" src=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/Task-3-2-1-Schematic.png\" alt=\"\" width=\"258\" height=\"784\" srcset=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/Task-3-2-1-Schematic.png 258w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/Task-3-2-1-Schematic-99x300.png 99w\" sizes=\"auto, (max-width: 258px) 100vw, 258px\" \/><\/p>\n<p>For this task, we are going to read the digital input using software. The objective is as follows:<\/p>\n<p style=\"padding-left: 30px\">When the user depresses a button, the red LED switches ON and stays ON (until the system is reset).<br \/>\nRemember &#8211; the input is connected to D4.<\/p>\n<p>Maybe unsurprisingly, we use a component called a <code>DigitalIn<\/code>.<\/p>\n<figure id=\"attachment_771\" aria-describedby=\"caption-attachment-771\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-771\" src=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/Task-3-2-1.png\" alt=\"\" width=\"600\" height=\"323\" srcset=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/Task-3-2-1.png 935w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/Task-3-2-1-300x162.png 300w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/Task-3-2-1-768x414.png 768w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><figcaption id=\"caption-attachment-771\" class=\"wp-caption-text\">Task 3.2.1<\/figcaption><\/figure>\n<pre class=\"lang:c++ decode:true \">#include \"mbed.h\"\r\n\r\nDigitalOut  red_led(D7);\r\nDigitalOut  yellow_led(D6);\r\nDigitalOut  green_led(D5);\r\nDigitalIn   SW1(D4);\r\n\r\nint main() {\r\n\r\n    \/\/Switch on Yellow and Green to indicate\r\n    \/\/that the code is running\r\n    yellow_led = 1;\r\n    green_led = 1;\r\n    red_led = 0; \/\/Set RED LED to OFF\r\n    \r\n    \/\/ Wait for SW1 to be pressed\r\n    while (SW1 == 0) { }\r\n    \r\n    red_led = 1;\t\/\/Turn ON LED\r\n    \r\n    while (1) { }\t\t\/\/Repeat forever\r\n}<\/pre>\n<p>Under the hood, there is a significant amount of work going on to set up the hardware in the right mode. The specifics are also vendor \/ board dependent.<\/p>\n<p>We benefit greatly from <strong>hardware abstraction<\/strong> provided by the mbed C++ classes <code>DigitalIn<\/code> and <code>DigitalOut<\/code>. mbed provide identical interfaces for all supported mbed compliant boards. This is an example of a <strong>device driver<\/strong>.<\/p>\n<p class=\"p1\">Once again, we use of the the component from mbed to make interfacing with hardware simple.<\/p>\n<p class=\"p1\"><code>DigitalIn SW1(D4);<\/code><\/p>\n<p class=\"p1\">where <code>SW1<\/code> is an instance of <code>DigitalIn<\/code>, which can read pin <code>D4<\/code>. A critical line in this code is as follows:<\/p>\n<p class=\"p1\"><code>while (SW1 == 0) { }<\/code><\/p>\n<p>While the digital input <code>SW1<\/code> is equal to zero, this code blocks the CPU in a <strong>tight polling loop<\/strong>. This is also known as <strong>spinning<\/strong>. This is <strong>NOT<\/strong> power or CPU efficient. Once the switch is pressed, an attempt to read <code>SW1<\/code> will return a <code>1<\/code> and so the CPU will <strong>unblock<\/strong>.<\/p>\n<blockquote><p>It is not always bad practise to monitor peripheral hardware this way. If delays are likely to be very short, it can even have some advantages. However, the time between switch presses is indeterminate in this case, so spinning becomes wasteful of CPU time and most of all, power.<\/p><\/blockquote>\n<figure id=\"attachment_773\" aria-describedby=\"caption-attachment-773\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-773\" src=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/Task-3-2-2.png\" alt=\"\" width=\"600\" height=\"257\" srcset=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/Task-3-2-2.png 935w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/Task-3-2-2-300x128.png 300w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/Task-3-2-2-768x329.png 768w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><figcaption id=\"caption-attachment-773\" class=\"wp-caption-text\">Task 3.2.2<\/figcaption><\/figure>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-774\" src=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/Task-3-2-2-Flowchart.png\" alt=\"\" width=\"154\" height=\"429\" srcset=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/Task-3-2-2-Flowchart.png 154w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/Task-3-2-2-Flowchart-108x300.png 108w\" sizes=\"auto, (max-width: 154px) 100vw, 154px\" \/><\/p>\n<p>You <em>might<\/em> have found this to be an unreliable solution (depending on how clean the switch contacts are).\u00a0In the next section, we will remind ourselves about \u201cswitch bounce\u201d and how to avoid it as this added\u00a0some additional complexity to our software.<\/p>\n<h2>Real World Signals<\/h2>\n<p>When working with physical hardware, both hardware and software engineers can take steps to reduce the probability of an erroneous input. In almost every case, errors are <em>probabilistic<\/em>. You can never engineer the probability to zero (ok, philosophical point maybe, but often it\u2019s a very real issue).<\/p>\n<blockquote><p>As engineers, we have to recognise and mitigate against such failures, and at least know the probability and impact of failure that risk can be managed. Many systems are not fully autonomous, where human operators follow a protocol that is designed to monitor, manage and mitigate against risk.<\/p><\/blockquote>\n<p>A consumer gadget can accept a higher chance of failure than a safety critical system such as an anti-lock braking system or fly-by-wire system in a commercial aircraft. Some medical devices have to work with small and noisy signals from the human body, and have to use sophisticated mathematics and software to manage the error.<\/p>\n<h3>Switch Bounce<\/h3>\n<p>The reality is that mechanical switches are not perfect. Most switches suffer switch bounce to some degree. As you can see in the second diagram opposite, the waveform is not a perfect step like the ideal.<\/p>\n<figure id=\"attachment_775\" aria-describedby=\"caption-attachment-775\" style=\"width: 321px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-775\" src=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/switch-bounce.png\" alt=\"\" width=\"321\" height=\"393\" srcset=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/switch-bounce.png 321w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/switch-bounce-245x300.png 245w\" sizes=\"auto, (max-width: 321px) 100vw, 321px\" \/><figcaption id=\"caption-attachment-775\" class=\"wp-caption-text\">Top &#8211; Ideal switch behaviour. Bottom &#8211; depicts actual electrical characteristics of a mechanical switch<\/figcaption><\/figure>\n<p>There are two common phenomena we much consider:<\/p>\n<p><strong>Noise<\/strong> &#8211; random signals superimposed on top of the waveform<\/p>\n<p><strong>Reactive effects<\/strong> &#8211; if you\u2019ve not covered reactance (maybe you&#8217;re a computer science student), it should suffice to say that perfect step waveforms are almost impossible &#8211; signals often rise as an exponential curve (although it might be very rapid)<\/p>\n<p>This reinforces the points that electronics is ultimately analog and signals are rarely ideal.<\/p>\n<p>A problem with such phenomena is that their occurrence is stochastic (random, probability based). An engineer must be mindful of such issues, and design systems to minimise the probability of such events occurring or causing malfunction, especially in safety critical systems.<\/p>\n<p>In the case of switch bounce, the exact nature is highly unpredictable. Consider the revised flow-chart below. This has added a delay after the first press is detected.<\/p>\n<figure id=\"attachment_778\" aria-describedby=\"caption-attachment-778\" style=\"width: 136px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-778\" src=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/Task-3-2-2-Flowchart-revised.png\" alt=\"\" width=\"136\" height=\"397\" srcset=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/Task-3-2-2-Flowchart-revised.png 136w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/Task-3-2-2-Flowchart-revised-103x300.png 103w\" sizes=\"auto, (max-width: 136px) 100vw, 136px\" \/><figcaption id=\"caption-attachment-778\" class=\"wp-caption-text\">Adding a delay to address the problem of switch bounce<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p class=\"p1\">\u00a0<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-779\" src=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/Task-30203.png\" alt=\"\" width=\"600\" height=\"329\" srcset=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/Task-30203.png 935w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/Task-30203-300x164.png 300w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/Task-30203-768x421.png 768w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>Adding the delay makes the system less responsive. This is often referred to as latency. This task illustrates some key points:<\/p>\n<ul>\n<li>electronic signals are rarely \u201cideal\u201d<\/li>\n<li>switch inputs suffer \u201cswitch bounce\u201d<\/li>\n<li>we sometimes have to make trade-offs, such as latency for reliability.<\/li>\n<\/ul>\n<h2>Non-Blocking Polling<\/h2>\n<p><em>A technique to read data from multiple input sources without blocking a thread of execution.<\/em><\/p>\n<p>In the figure below, each device is polled to see if it has any available data (or if there has been any change). If yes, then the value is retrieved and stored. The next device is then polled.<\/p>\n<figure id=\"attachment_780\" aria-describedby=\"caption-attachment-780\" style=\"width: 278px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-780\" src=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/Non-blocking-pollingloop-flowchart.png\" alt=\"\" width=\"278\" height=\"379\" srcset=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/Non-blocking-pollingloop-flowchart.png 278w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/Non-blocking-pollingloop-flowchart-220x300.png 220w\" sizes=\"auto, (max-width: 278px) 100vw, 278px\" \/><figcaption id=\"caption-attachment-780\" class=\"wp-caption-text\">Note how hardware is polled (status read) without looping back and blocking.<\/figcaption><\/figure>\n<p>This method is an improvement over the busy-wait approach as it does not block the \u201cthread\u201d of execution, so all devices are queried at (typically) high rates.<\/p>\n<p>This method does have some disadvantages however. The loop must repeat fast enough to read all devices before data is lost. This again means CPU cycles and power are being consumed even where there is no new input to process. Furthermore, the presence of conditional statements (if\/while\/switch) means the execution path through the code will vary, and thus the loop timing is likely to jitter. This can cause problems where data must be read at fixed intervals (as we will discover later).<\/p>\n<p>In the next task we implement such a methodology where we poll two devices: a timer and a switch. You should <strong>read<\/strong> the <a href=\"https:\/\/os.mbed.com\/docs\/mbed-os\/v5.14\/apis\/timer.html\" target=\"_blank\" rel=\"noopener\">Mbed-os documentation for the <code>Timer<\/code> class<\/a> before you attempt the next task. This is quite a tough (but important) task, so see the tips given below as well.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-781\" src=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/Task-3-2-4.png\" alt=\"\" width=\"600\" height=\"541\" srcset=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/Task-3-2-4.png 935w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/Task-3-2-4-300x270.png 300w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/Task-3-2-4-768x692.png 768w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<figure id=\"attachment_784\" aria-describedby=\"caption-attachment-784\" style=\"width: 268px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-784\" src=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/Task-3-2-4-flowchart.png\" alt=\"\" width=\"268\" height=\"632\" srcset=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/Task-3-2-4-flowchart.png 268w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/Task-3-2-4-flowchart-127x300.png 127w\" sizes=\"auto, (max-width: 268px) 100vw, 268px\" \/><figcaption id=\"caption-attachment-784\" class=\"wp-caption-text\">Modified flow chart that toggles a LED and repeats. This uses busy-wait so will only work for a single input switch<\/figcaption><\/figure>\n<p><strong>TIPS<\/strong><\/p>\n<p>For this task, each switch and timer combination can be seen as a separate finite state machine.\u00a0The basic code for a single switch\/timer can be found here <a href=\"https:\/\/os.mbed.com\/teams\/University-of-Plymouth-Stage-2-and-3\/code\/Task324\/\" target=\"_blank\" rel=\"noopener\">https:\/\/os.mbed.com\/teams\/University-of-Plymouth-Stage-2-and-3\/code\/Task324\/<\/a><\/p>\n<blockquote><p>Try and see the relationship between this code and the state diagram below. <em>This is important<\/em><\/p><\/blockquote>\n<p>A solution is here: <a href=\"https:\/\/os.mbed.com\/teams\/University-of-Plymouth-Stage-2-and-3\/code\/Task324Solution\/\" target=\"_blank\" rel=\"noopener\">https:\/\/os.mbed.com\/teams\/University-of-Plymouth-Stage-2-and-3\/code\/Task324Solution\/<\/a>. Only look at this if you are completely stuck.<\/p>\n<figure id=\"attachment_785\" aria-describedby=\"caption-attachment-785\" style=\"width: 728px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-785\" src=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/FSM-For-Task-3-2-4.png\" alt=\"\" width=\"728\" height=\"387\" srcset=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/FSM-For-Task-3-2-4.png 728w, https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-content\/uploads\/sites\/94\/2019\/09\/FSM-For-Task-3-2-4-300x159.png 300w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><figcaption id=\"caption-attachment-785\" class=\"wp-caption-text\">State Diagram for Task 3.2.4 &#8211; single switch SW and LED. For state transitions, the format is: {input condition \/ (mealy) Output}<\/figcaption><\/figure>\n<p>If you managed the task above, well done. I suggest you make a note of the solution for future reference. <em>The software pattern is reusable\u00a0for other similar tasks<\/em>.<\/p>\n<h2>Self-Study Challenge: Finite State Machines in C<\/h2>\n<p>This might be a good time to review the code solution above and observe how the switch-case is used to implement a state machine. Maybe make notes in your log books on implementation of software state machines using a switch-case. The following task is designed to further test your own understanding<\/p>\n<h3>Self-Directed Task<\/h3>\n<p>Using the same hardware as above, write a new project to do the following:<\/p>\n<ul>\n<li>On power up, the Green LED should flash continuously at a rate of once a second (1Hz).<\/li>\n<li>Pressing SW1 should reduce the flashing rate (frequency)<\/li>\n<li>Pressing SW2 should increase the flashing rate<\/li>\n<li>Pressing SW1 and SW2 together should reset the frequency to 1Hz<\/li>\n<li>Take steps to avoid switch bounce for both switches. Poll a timer to check the time. Do not use <code>wait()<\/code><\/li>\n<li>Use one state machine per switch \/ timer pair. Maybe show the tutor your state-diagram before you write the code.<\/li>\n<\/ul>\n<p>Document this in your log book \/ notes. Include a state diagram. Remember that your state diagram has two inputs, a switch and a timer, although you won\u2019t necessarily poll both in each state.<\/p>\n<p><strong>Tips:<\/strong><\/p>\n<p>State diagrams can be sketched on paper, photographed with a smartphone or tablet and inserted into your logbook. I recommend using document scanning facility in OneDrive (for Android and iOS) to make this much more seamless.<\/p>\n<p>You are strongly advised to complete this task before the next lab session. Remember a taught module is 200Hrs. This should be approximately 16 hours \/ week<\/p>\n<p>4Hrs \/ week lectures<\/p>\n<p>4Hrs \/ week practicals<\/p>\n<p>8+hrs\/week self study<\/p>\n<h3><strong>Advanced Task<\/strong><\/h3>\n<p>The state machines above are Mealy Machines (outputs are changed on state-transitions). If you are really curious, can you re-write this task as a Moore Machine? Hint: Split the state machine into two distinct switch-case blocks, one for the next state and the next for the output.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/blogs.plymouth.ac.uk\/embedded-systems\/microcontrollers\/mbed-os-2\/courses\/level-5-embedded-and-real-time-systems\/performing-real-time-tasks-with-interrupts\/\">Next &#8211; Performing Real-Time Tasks with Interrupts<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Table of Contents In this section, we will look at digital inputs, and how we might use them to control digital outputs. We will be using a simple \u201cpush-to-make switch\u201d to generate a single digital bit of data. Activity 3.1 &#8211; Simple Switch Input Remember that a single digital signal is either ON or OFF.&hellip; <a class=\"more-link\" href=\"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/microcontrollers\/mbed-os-2\/courses\/level-5-embedded-and-real-time-systems\/managing-multiple-inputs-and-outputs\/\">Continue reading <span class=\"screen-reader-text\">Managing Multiple Inputs and Outputs<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":719,"menu_order":2,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-764","page","type-page","status-publish","hentry","entry"],"_links":{"self":[{"href":"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-json\/wp\/v2\/pages\/764","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=764"}],"version-history":[{"count":9,"href":"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-json\/wp\/v2\/pages\/764\/revisions"}],"predecessor-version":[{"id":827,"href":"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-json\/wp\/v2\/pages\/764\/revisions\/827"}],"up":[{"embeddable":true,"href":"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-json\/wp\/v2\/pages\/719"}],"wp:attachment":[{"href":"https:\/\/blogs.plymouth.ac.uk\/embedded-systems\/wp-json\/wp\/v2\/media?parent=764"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}