<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2535795214191795882</id><updated>2024-11-01T00:09:34.974-07:00</updated><category term="Arduino"/><category term="basic electronics tutorials"/><category term="pic tutorials"/><category term="projects"/><category term="power supply"/><category term="rich your mind"/><category term="about me"/><title type='text'>Zouhair electronics</title><subtitle type='html'>Microcontrollers and Electronics Project Blog</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://moroccoele.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://moroccoele.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>zouhair</name><uri>http://www.blogger.com/profile/03215618839043737171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>65</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2535795214191795882.post-3672156776227212986</id><published>2019-06-25T00:17:00.002-07:00</published><updated>2019-06-25T02:25:20.275-07:00</updated><title type='text'>Arduino bluetouth car control </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;background-color: white; color: #151515; font-family: &amp;quot;montserrat&amp;quot;; font-size: 14px;&quot;&gt;In this project I will show you how to create&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;background-color: white; color: #151515; font-family: Montserrat; font-size: 14px; outline: 0px; transition: all 0.3s ease 0s;&quot;&gt;Smartphone (Bluetooth) Controlled Car Using Arduino.&amp;nbsp;&lt;/b&gt;&lt;span style=&quot;background-color: white; color: #151515; font-family: &amp;quot;montserrat&amp;quot;; font-size: 14px;&quot;&gt;This Car can be controller using an Android Application.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #151515; font-family: &amp;quot;montserrat&amp;quot;; font-size: 14px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #151515; font-family: &amp;quot;montserrat&amp;quot;; font-size: 14px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 style=&quot;background-color: white; color: #2c3e50; font-family: &amp;quot;playfair display&amp;quot;, serif; margin: 0px 0px 15px; outline: 0px; padding: 0px; position: relative; transition: all 0.3s ease 0s;&quot;&gt;
&lt;b&gt;
Block Diagram&lt;/b&gt;&lt;/h3&gt;
&lt;div style=&quot;background-color: white; color: #151515; font-family: Montserrat; font-size: 14px; margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
Let me explain the Design and Working of this project using the following Block Diagrams.&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #151515; font-family: Montserrat; font-size: 14px; margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7P_BDK4aFtaqyoW8wb_oqBnymF4f7sxa4mdROf3-iAkPtIs41FlToFov-Gj-P-rYUJ6spsQz5n0nDebX75z1Z-ht1XrZomZReXvAgXZ_zjc1tnF_qXBWWZcfNKDo9e4Mw-bDad-vgyH5D/s1600/ard.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;776&quot; data-original-width=&quot;1004&quot; height=&quot;308&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7P_BDK4aFtaqyoW8wb_oqBnymF4f7sxa4mdROf3-iAkPtIs41FlToFov-Gj-P-rYUJ6spsQz5n0nDebX75z1Z-ht1XrZomZReXvAgXZ_zjc1tnF_qXBWWZcfNKDo9e4Mw-bDad-vgyH5D/s400/ard.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #151515; font-family: Montserrat; font-size: 14px; margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;The Project is having Mainly 5 Blocks. Refer&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;color: #151515; font-family: Montserrat; font-size: 14px; outline: 0px; transition: all 0.3s ease 0s;&quot;&gt;Figure 1&lt;/b&gt;&lt;br /&gt;
&lt;b style=&quot;color: #151515; font-family: Montserrat; font-size: 14px; outline: 0px; transition: all 0.3s ease 0s;&quot;&gt;1. Bluetooth Module&lt;/b&gt;&lt;br /&gt;
&lt;b style=&quot;color: #151515; font-family: Montserrat; font-size: 14px; outline: 0px; transition: all 0.3s ease 0s;&quot;&gt;2. Arduino UNO&lt;/b&gt;&lt;br /&gt;
&lt;b style=&quot;color: #151515; font-family: Montserrat; font-size: 14px; outline: 0px; transition: all 0.3s ease 0s;&quot;&gt;3. DC Motor Driver&lt;/b&gt;&lt;br /&gt;
&lt;b style=&quot;color: #151515; font-family: Montserrat; font-size: 14px; outline: 0px; transition: all 0.3s ease 0s;&quot;&gt;4. DC Motor 1&lt;/b&gt;&lt;br /&gt;
&lt;b style=&quot;color: #151515; font-family: Montserrat; font-size: 14px; outline: 0px; transition: all 0.3s ease 0s;&quot;&gt;5. DC Motor 2&lt;/b&gt;&lt;br /&gt;
&lt;br style=&quot;outline: 0px; transition: all 0.3s ease 0s;&quot; /&gt;
&lt;b style=&quot;color: #151515; font-family: Montserrat; font-size: 14px; outline: 0px; transition: all 0.3s ease 0s;&quot;&gt;Bluetooth Module&lt;/b&gt;&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;: This block is mainly responsible for establishing the connection between Andriod mobile phone and the Circuit&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;outline: 0px; transition: all 0.3s ease 0s;&quot; /&gt;
&lt;b style=&quot;color: #151515; font-family: Montserrat; font-size: 14px; outline: 0px; transition: all 0.3s ease 0s;&quot;&gt;Arduino UNO:&amp;nbsp;&lt;/b&gt;&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;Arduino is the brain of this project. This will control and co-ordinate all the other components connected with this project.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;outline: 0px; transition: all 0.3s ease 0s;&quot; /&gt;
&lt;b style=&quot;color: #151515; font-family: Montserrat; font-size: 14px; outline: 0px; transition: all 0.3s ease 0s;&quot;&gt;DC Motor Driver:&amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;We use this module as Arduino will not be able to provide the required Voltage and Current to Rotate the DC motor by alone. Digital Pins of Arduino will be connected to the input section of DC Motor Driver. This section will rotate the DC motors according the Volages received on the Arduino digital pins.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;outline: 0px; transition: all 0.3s ease 0s;&quot; /&gt;
&lt;b style=&quot;color: #151515; font-family: Montserrat; font-size: 14px; outline: 0px; transition: all 0.3s ease 0s;&quot;&gt;DC Motor 1 &amp;amp;&lt;/b&gt;&lt;b style=&quot;color: #151515; font-family: Montserrat; font-size: 14px; outline: 0px; transition: all 0.3s ease 0s;&quot;&gt;&amp;nbsp;DC Motor 2:&amp;nbsp;&lt;/b&gt;&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;These two DC motors will decide the direction of the Car. This car can move to the following directions.&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;color: #151515; font-family: Montserrat; font-size: 14px; margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
1.Forward Direction&lt;/div&gt;
&lt;div style=&quot;color: #151515; font-family: Montserrat; font-size: 14px; margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
2.Reverse Direction&lt;/div&gt;
&lt;div style=&quot;color: #151515; font-family: Montserrat; font-size: 14px; margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
3.Forward Right&lt;/div&gt;
&lt;div style=&quot;color: #151515; font-family: Montserrat; font-size: 14px; margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
4.Forward Left&lt;/div&gt;
&lt;div style=&quot;color: #151515; font-family: Montserrat; font-size: 14px; margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; color: #151515; font-family: Montserrat; font-size: 14px; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUuPXNMoYr-LgGKCfUWC3WC2nb8JjhFpt3nuQYnM-IHZk5TS7cA_OcdfamcggzdrPv6HLVZnXKlGhO6SldchlWLaYEzl-0gYtVYlM3HZnLrauIjEGYRatMd75uLZ5F8Il2DNtlXamL7Mi2/s1600/2.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;768&quot; data-original-width=&quot;1024&quot; height=&quot;480&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUuPXNMoYr-LgGKCfUWC3WC2nb8JjhFpt3nuQYnM-IHZk5TS7cA_OcdfamcggzdrPv6HLVZnXKlGhO6SldchlWLaYEzl-0gYtVYlM3HZnLrauIjEGYRatMd75uLZ5F8Il2DNtlXamL7Mi2/s640/2.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; color: #151515; font-family: Montserrat; font-size: 14px; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; color: #151515; font-family: Montserrat; font-size: 14px; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #151515; font-family: Montserrat; font-size: 14px; margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
Now Lets talk little about the Android Application that we are going to use for this project you can using MTinventor app to creat application for this robot next time i will explain how to using MT inventor app its easy to use&lt;/div&gt;
&lt;div style=&quot;color: #151515; font-family: Montserrat; font-size: 14px; margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
Now let me try to explain the working of this project using&amp;nbsp;&lt;b style=&quot;outline: 0px; transition: all 0.3s ease 0s;&quot;&gt;Figure 3&lt;/b&gt;. The Circuit will get ready to receive commands once the Android Application is successfully paired with the Bluetooth Module HC-05.&lt;br /&gt;
When a button is pressed(Suppose Forward Button) a value will be sent(Value &quot;F&quot;) and it will be received by the Bluetooth Module. This Value again will be sent to Arduino UNO by the Bluetooth Module.&lt;br /&gt;
Once Arduino receives the Value it will check what action need to be taken according to the value received. In this case Arduino will set digital pins 10 to 13 in such a way that the DC Motor will rotate in&amp;nbsp; forward direction. The digital pins 10-13 of Arduino UNO is connected to the&amp;nbsp; input pins of DC Motor Driver M1.a,M1.b,M2.a and M2.b respectively. Output pins of DC Motor driver will be connected to the DC Motors. This way Arduino will start to control the DC Motors using their Digital pins 10-13&lt;br /&gt;
The Table shown below explains the Value and action that are used for this project.&lt;/div&gt;
&lt;div style=&quot;color: #151515; font-family: Montserrat; font-size: 14px; margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;table cellpadding=&quot;4&quot; cellspacing=&quot;0&quot; style=&quot;border-spacing: 0px; color: #151515; font-size: 14px; margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;&lt;tbody style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;tr style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot; valign=&quot;top&quot;&gt;&lt;td style=&quot;border-bottom: 1px solid rgb(0, 0, 0); border-left: 1px solid rgb(0, 0, 0); border-right: none; border-top: 1px solid rgb(0, 0, 0); margin: 0px; outline: 0px; padding: 0.1cm 0cm 0.1cm 0.1cm; transition: all 0.3s ease 0s;&quot; width=&quot;50%&quot;&gt;&lt;b style=&quot;outline: 0px; transition: all 0.3s ease 0s;&quot;&gt;Value&lt;/b&gt;&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(0, 0, 0); margin: 0px; outline: 0px; padding: 0.1cm; transition: all 0.3s ease 0s;&quot; width=&quot;50%&quot;&gt;&lt;b style=&quot;outline: 0px; transition: all 0.3s ease 0s;&quot;&gt;Action&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot; valign=&quot;top&quot;&gt;&lt;td style=&quot;border-bottom: 1px solid rgb(0, 0, 0); border-left: 1px solid rgb(0, 0, 0); border-right: none; border-top: none; margin: 0px; outline: 0px; padding: 0cm 0cm 0.1cm 0.1cm; transition: all 0.3s ease 0s;&quot; width=&quot;50%&quot;&gt;F&lt;/td&gt;&lt;td style=&quot;border-bottom: 1px solid rgb(0, 0, 0); border-left: 1px solid rgb(0, 0, 0); border-right: 1px solid rgb(0, 0, 0); border-top: none; margin: 0px; outline: 0px; padding: 0cm 0.1cm 0.1cm; transition: all 0.3s ease 0s;&quot; width=&quot;50%&quot;&gt;Forward&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot; valign=&quot;top&quot;&gt;&lt;td style=&quot;border-bottom: 1px solid rgb(0, 0, 0); border-left: 1px solid rgb(0, 0, 0); border-right: none; border-top: none; margin: 0px; outline: 0px; padding: 0cm 0cm 0.1cm 0.1cm; transition: all 0.3s ease 0s;&quot; width=&quot;50%&quot;&gt;B&lt;/td&gt;&lt;td style=&quot;border-bottom: 1px solid rgb(0, 0, 0); border-left: 1px solid rgb(0, 0, 0); border-right: 1px solid rgb(0, 0, 0); border-top: none; margin: 0px; outline: 0px; padding: 0cm 0.1cm 0.1cm; transition: all 0.3s ease 0s;&quot; width=&quot;50%&quot;&gt;Backward&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot; valign=&quot;top&quot;&gt;&lt;td style=&quot;border-bottom: 1px solid rgb(0, 0, 0); border-left: 1px solid rgb(0, 0, 0); border-right: none; border-top: none; margin: 0px; outline: 0px; padding: 0cm 0cm 0.1cm 0.1cm; transition: all 0.3s ease 0s;&quot; width=&quot;50%&quot;&gt;S&lt;/td&gt;&lt;td style=&quot;border-bottom: 1px solid rgb(0, 0, 0); border-left: 1px solid rgb(0, 0, 0); border-right: 1px solid rgb(0, 0, 0); border-top: none; margin: 0px; outline: 0px; padding: 0cm 0.1cm 0.1cm; transition: all 0.3s ease 0s;&quot; width=&quot;50%&quot;&gt;Stop&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot; valign=&quot;top&quot;&gt;&lt;td style=&quot;border-bottom: 1px solid rgb(0, 0, 0); border-left: 1px solid rgb(0, 0, 0); border-right: none; border-top: none; margin: 0px; outline: 0px; padding: 0cm 0cm 0.1cm 0.1cm; transition: all 0.3s ease 0s;&quot; width=&quot;50%&quot;&gt;R&lt;/td&gt;&lt;td style=&quot;border-bottom: 1px solid rgb(0, 0, 0); border-left: 1px solid rgb(0, 0, 0); border-right: 1px solid rgb(0, 0, 0); border-top: none; margin: 0px; outline: 0px; padding: 0cm 0.1cm 0.1cm; transition: all 0.3s ease 0s;&quot; width=&quot;50%&quot;&gt;Right&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot; valign=&quot;top&quot;&gt;&lt;td style=&quot;border-bottom: 1px solid rgb(0, 0, 0); border-left: 1px solid rgb(0, 0, 0); border-right: none; border-top: none; margin: 0px; outline: 0px; padding: 0cm 0cm 0.1cm 0.1cm; transition: all 0.3s ease 0s;&quot; width=&quot;50%&quot;&gt;L&lt;/td&gt;&lt;td style=&quot;border-bottom: 1px solid rgb(0, 0, 0); border-left: 1px solid rgb(0, 0, 0); border-right: 1px solid rgb(0, 0, 0); border-top: none; margin: 0px; outline: 0px; padding: 0cm 0.1cm 0.1cm; transition: all 0.3s ease 0s;&quot; width=&quot;50%&quot;&gt;Left&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;h3 style=&quot;color: #2c3e50; font-family: &amp;quot;Playfair Display&amp;quot;, serif; font-size: 14px; font-weight: 400; margin: 0px 0px 15px; outline: 0px; padding: 0px; position: relative; transition: all 0.3s ease 0s;&quot;&gt;
&lt;b style=&quot;outline: 0px; transition: all 0.3s ease 0s;&quot;&gt;Components Required&lt;/b&gt;&lt;/h3&gt;
&lt;div style=&quot;color: #151515; font-family: Montserrat; font-size: 14px; margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;b style=&quot;outline: 0px; transition: all 0.3s ease 0s;&quot;&gt;Figure 4&lt;/b&gt;&amp;nbsp;explains the components required for this project. You can buy all these components from websites like Amazon/E-Bay etc&lt;br /&gt;
&lt;br style=&quot;outline: 0px; transition: all 0.3s ease 0s;&quot; /&gt;
&lt;br style=&quot;outline: 0px; transition: all 0.3s ease 0s;&quot; /&gt;
&lt;ul style=&quot;line-height: 1.5; margin: 0.5em 0px; outline: 0px; padding: 0px 2.5em 0px 15px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;li style=&quot;line-height: 1.5; list-style-type: disc; margin: 5px 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;&lt;b style=&quot;outline: 0px; transition: all 0.3s ease 0s;&quot;&gt;Arduino UNO.......................&lt;a href=&quot;https://amzn.to/2GdwiUB&quot; style=&quot;color: #54a8d0; margin: 0px; outline: 0px; padding: 0px; text-decoration-line: none; transition: all 0.3s ease 0s;&quot; target=&quot;_blank&quot;&gt;Amazon.com&amp;nbsp;&lt;/a&gt;/&amp;nbsp;&lt;a href=&quot;https://amzn.to/2D5lg1R&quot; style=&quot;color: #54a8d0; margin: 0px; outline: 0px; padding: 0px; text-decoration-line: none; transition: all 0.3s ease 0s;&quot; target=&quot;_blank&quot;&gt;Amazon.in&amp;nbsp;&lt;/a&gt;&lt;/b&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 1.5; list-style-type: disc; margin: 5px 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;&lt;b style=&quot;outline: 0px; transition: all 0.3s ease 0s;&quot;&gt;Motor Driver L293D............&lt;a href=&quot;https://amzn.to/2D9RFEl&quot; style=&quot;color: #54a8d0; margin: 0px; outline: 0px; padding: 0px; text-decoration-line: none; transition: all 0.3s ease 0s;&quot; target=&quot;_blank&quot;&gt;Amazon.com&amp;nbsp;&lt;/a&gt;/&amp;nbsp;&lt;a href=&quot;https://amzn.to/2I9IRCA&quot; style=&quot;color: #54a8d0; margin: 0px; outline: 0px; padding: 0px; text-decoration-line: none; transition: all 0.3s ease 0s;&quot; target=&quot;_blank&quot;&gt;Amazon.in&amp;nbsp;&lt;/a&gt;&lt;/b&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 1.5; list-style-type: disc; margin: 5px 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;&lt;b style=&quot;outline: 0px; transition: all 0.3s ease 0s;&quot;&gt;Bluetooth Module HC-05.....&lt;a href=&quot;https://amzn.to/2I7tRVG&quot; style=&quot;color: #54a8d0; margin: 0px; outline: 0px; padding: 0px; text-decoration-line: none; transition: all 0.3s ease 0s;&quot; target=&quot;_blank&quot;&gt;Amazon.com&amp;nbsp;&lt;/a&gt;/&amp;nbsp;&lt;a href=&quot;https://amzn.to/2KmRXO9&quot; style=&quot;color: #54a8d0; margin: 0px; outline: 0px; padding: 0px; text-decoration-line: none; transition: all 0.3s ease 0s;&quot; target=&quot;_blank&quot;&gt;Amazon.in&amp;nbsp;&lt;/a&gt;&lt;/b&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 1.5; list-style-type: disc; margin: 5px 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;&lt;b style=&quot;outline: 0px; transition: all 0.3s ease 0s;&quot;&gt;Jumper Wires........................&lt;a href=&quot;https://amzn.to/2X0U3F8&quot; style=&quot;color: #54a8d0; margin: 0px; outline: 0px; padding: 0px; text-decoration-line: none; transition: all 0.3s ease 0s;&quot; target=&quot;_blank&quot;&gt;Amazon.com&amp;nbsp;&lt;/a&gt;/&amp;nbsp;&lt;a href=&quot;https://amzn.to/2D7Jg4b&quot; style=&quot;color: #54a8d0; margin: 0px; outline: 0px; padding: 0px; text-decoration-line: none; transition: all 0.3s ease 0s;&quot; target=&quot;_blank&quot;&gt;Amazon.in&amp;nbsp;&lt;/a&gt;&lt;/b&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 1.5; list-style-type: disc; margin: 5px 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;&lt;b style=&quot;outline: 0px; transition: all 0.3s ease 0s;&quot;&gt;Two Wheel Drive Robot Car Chassis with DC Motor....&lt;a href=&quot;https://amzn.to/2I70OSp&quot; style=&quot;color: #54a8d0; margin: 0px; outline: 0px; padding: 0px; text-decoration-line: none; transition: all 0.3s ease 0s;&quot; target=&quot;_blank&quot;&gt;Amazon.com&amp;nbsp;&lt;/a&gt;/&amp;nbsp;&lt;a href=&quot;https://amzn.to/2KqYasr&quot; style=&quot;color: #54a8d0; margin: 0px; outline: 0px; padding: 0px; text-decoration-line: none; transition: all 0.3s ease 0s;&quot; target=&quot;_blank&quot;&gt;Amazon.in&amp;nbsp;&lt;/a&gt;&lt;/b&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 1.5; list-style-type: disc; margin: 5px 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;&lt;b style=&quot;outline: 0px; transition: all 0.3s ease 0s;&quot;&gt;Bread Board..........................&lt;a href=&quot;https://amzn.to/2ItH36V&quot; style=&quot;color: #54a8d0; margin: 0px; outline: 0px; padding: 0px; text-decoration-line: none; transition: all 0.3s ease 0s;&quot; target=&quot;_blank&quot;&gt;Amazon.com&amp;nbsp;&lt;/a&gt;/&amp;nbsp;&lt;a href=&quot;https://amzn.to/2KxWehI&quot; style=&quot;color: #54a8d0; margin: 0px; outline: 0px; padding: 0px; text-decoration-line: none; transition: all 0.3s ease 0s;&quot; target=&quot;_blank&quot;&gt;Amazon.in&amp;nbsp;&lt;/a&gt;&lt;/b&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 1.5; list-style-type: disc; margin: 5px 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;&lt;b style=&quot;outline: 0px; transition: all 0.3s ease 0s;&quot;&gt;9V Battery.............................&lt;a href=&quot;https://amzn.to/2KwW9v4&quot; style=&quot;color: #54a8d0; margin: 0px; outline: 0px; padding: 0px; text-decoration-line: none; transition: all 0.3s ease 0s;&quot; target=&quot;_blank&quot;&gt;Amazon.com&amp;nbsp;&lt;/a&gt;/&amp;nbsp;&lt;a href=&quot;https://amzn.to/2D5ECUl&quot; style=&quot;color: #54a8d0; margin: 0px; outline: 0px; padding: 0px; text-decoration-line: none; transition: all 0.3s ease 0s;&quot; target=&quot;_blank&quot;&gt;Amazon.in&amp;nbsp;&lt;/a&gt;&lt;/b&gt;&lt;/li&gt;
&lt;li style=&quot;line-height: 1.5; list-style-type: disc; margin: 5px 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;&lt;b style=&quot;outline: 0px; transition: all 0.3s ease 0s;&quot;&gt;9v Battery Clip with Male Dc Plug for Arduino.............&lt;a href=&quot;https://amzn.to/2P01KZ5&quot; style=&quot;color: #54a8d0; margin: 0px; outline: 0px; padding: 0px; text-decoration-line: none; transition: all 0.3s ease 0s;&quot; target=&quot;_blank&quot;&gt;Amazon.com&amp;nbsp;&lt;/a&gt;/&amp;nbsp;&lt;a href=&quot;https://amzn.to/2D5ECUl&quot; style=&quot;color: #54a8d0; margin: 0px; outline: 0px; padding: 0px; text-decoration-line: none; transition: all 0.3s ease 0s;&quot; target=&quot;_blank&quot;&gt;Amazon.in&amp;nbsp;&lt;/a&gt;&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;b style=&quot;outline: 0px; transition: all 0.3s ease 0s;&quot;&gt;&lt;i style=&quot;outline: 0px; transition: all 0.3s ease 0s;&quot;&gt;&lt;a href=&quot;https://www.amazon.in/shop/robots-thenextspeciesonearth&quot; style=&quot;color: #54a8d0; margin: 0px; outline: 0px; padding: 0px; text-decoration-line: none; transition: all 0.3s ease 0s;&quot; target=&quot;_blank&quot;&gt;Visit&amp;nbsp;&lt;/a&gt;our&amp;nbsp;&lt;a href=&quot;https://www.amazon.in/shop/robots-thenextspeciesonearth&quot; style=&quot;color: #54a8d0; margin: 0px; outline: 0px; padding: 0px; text-decoration-line: none; transition: all 0.3s ease 0s;&quot; target=&quot;_blank&quot;&gt;Amazon.in(India)&lt;/a&gt;&amp;nbsp;Store to view and purchase recommended products&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br style=&quot;outline: 0px; transition: all 0.3s ease 0s;&quot; /&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;br style=&quot;outline: 0px; transition: all 0.3s ease 0s;&quot; /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; color: #151515; font-family: Montserrat; font-size: 14px; margin: 0px; outline: 0px; padding: 0px; text-align: center; transition: all 0.3s ease 0s;&quot;&gt;
&lt;/div&gt;
&lt;h3 style=&quot;color: #2c3e50; font-family: &amp;quot;Playfair Display&amp;quot;, serif; font-size: 14px; font-weight: 400; margin: 0px 0px 15px; outline: 0px; padding: 0px; position: relative; transition: all 0.3s ease 0s;&quot;&gt;
&lt;b style=&quot;outline: 0px; transition: all 0.3s ease 0s;&quot;&gt;&amp;nbsp;Circuit Diagram&lt;/b&gt;&lt;/h3&gt;
&lt;div style=&quot;color: #151515; font-family: Montserrat; font-size: 14px; margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
Complete the connection as shown in figure 5.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #151515; font-family: Montserrat; font-size: 14px; margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #151515; font-family: Montserrat; font-size: 14px; margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
Now you are ready to upload the program to you Arduino.&lt;/div&gt;
&lt;div style=&quot;color: #151515; font-family: Montserrat; font-size: 14px; margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
Note:- Make sure to remove the wire that is connected to the receive pin(Rx.0) of Arduino before uploading the Program and connect it back once program is uploaded succesfully.&lt;/div&gt;
&lt;div style=&quot;color: #151515; font-family: Montserrat; font-size: 14px; margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzSbV2PsfMlDN2wbo0IzIieo6SIo_P427RzcXklOpTMVE-Pe8FEHxKZmW7bHR32laqbK3l3WcMuvQUJ_XQ2nkDQooP4fFejAuD_1l_YYoFzjfI3JNLjHhy1WALSaK9nDYZEpYMfggMF3-J/s1600/arddddd.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;181&quot; data-original-width=&quot;276&quot; height=&quot;419&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzSbV2PsfMlDN2wbo0IzIieo6SIo_P427RzcXklOpTMVE-Pe8FEHxKZmW7bHR32laqbK3l3WcMuvQUJ_XQ2nkDQooP4fFejAuD_1l_YYoFzjfI3JNLjHhy1WALSaK9nDYZEpYMfggMF3-J/s640/arddddd.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;color: #151515; font-family: Montserrat; font-size: 14px; margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
program :&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;/control robot car by using bleuthooth this project created by charaf zouhair for my daughter fatim zahra&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int state;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;int motorleftA=30;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;int motorleftB=31;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;int motorrightA=32;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;int motorrightB=33;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;int motorenable1=34;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;int motorenable2=35;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;void setup(){&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; pinMode(motorleftA,OUTPUT);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; pinMode(motorleftB,OUTPUT);&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; pinMode(motorrightA,OUTPUT);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; pinMode(motorrightB,OUTPUT);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; pinMode(motorenable1,OUTPUT);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; pinMode(motorenable2,OUTPUT);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; digitalWrite(motorenable1,HIGH);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; digitalWrite(motorenable2,HIGH);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; Serial.begin(9600);&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;void loop(){&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; if (Serial.available()&amp;gt;0){&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; state=Serial.read();&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp;}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp;if (state==&#39;F&#39;){&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; digitalWrite(motorleftA,HIGH);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; digitalWrite(motorleftB,LOW);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; digitalWrite(motorrightA,HIGH),&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; digitalWrite(motorrightB,LOW);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; Serial.println(&quot;go forward&quot;);}&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; else if(state==&#39;B&#39;){&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; digitalWrite(motorleftA,LOW);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; digitalWrite(motorleftB,HIGH);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; digitalWrite(motorrightA,LOW);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; digitalWrite(motorrightB,HIGH);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; Serial.println(&quot;go back&quot;); }&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; else if (state==&#39;R&#39;){&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; digitalWrite(motorleftA,HIGH);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; digitalWrite(motorleftB,LOW);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; digitalWrite(motorrightA,LOW);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; digitalWrite(motorrightB,LOW);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Serial.println(&quot;turn right&quot;);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; else if(state==&#39;L&#39;){&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; digitalWrite(motorleftA,LOW);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; digitalWrite(motorleftB,LOW);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; digitalWrite(motorrightA,HIGH);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; digitalWrite(motorrightB,LOW);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Serial.println(&quot;turn left&quot;);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; else if(state==&#39;S&#39;){&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; digitalWrite(motorleftA,LOW);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; digitalWrite(motorleftB,LOW);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; digitalWrite(motorrightA,LOW);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; digitalWrite(motorrightB,LOW);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Serial.println(&quot;STOP&quot;);&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px; outline: 0px; padding: 0px; transition: all 0.3s ease 0s;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;montserrat&amp;quot;;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://moroccoele.blogspot.com/feeds/3672156776227212986/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2535795214191795882/3672156776227212986' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/3672156776227212986'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/3672156776227212986'/><link rel='alternate' type='text/html' href='http://moroccoele.blogspot.com/2019/06/arduino-bluetouth-car-control.html' title='Arduino bluetouth car control '/><author><name>zouhair</name><uri>http://www.blogger.com/profile/03215618839043737171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7P_BDK4aFtaqyoW8wb_oqBnymF4f7sxa4mdROf3-iAkPtIs41FlToFov-Gj-P-rYUJ6spsQz5n0nDebX75z1Z-ht1XrZomZReXvAgXZ_zjc1tnF_qXBWWZcfNKDo9e4Mw-bDad-vgyH5D/s72-c/ard.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2535795214191795882.post-200089233620006666</id><published>2017-03-01T07:34:00.002-08:00</published><updated>2017-03-01T07:34:17.345-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Arduino"/><title type='text'>Getting and Using Arduino Serial Input</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
This part of the Arduino programming course shows how to get data into an Arduino sketch from the serial port. Data can be sent to the Arduino from the Serial Monitor window in the Arduino IDE.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
A user can enter data in the input field in the serial monitor window to send values and data to the Arduino. Any serial program, or even a custom serial application can be used to send data to the Arduino instead of using the Serial Monitor window.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Except for&amp;nbsp;&lt;a href=&quot;https://startingelectronics.org/software/arduino/learn-to-program-course/13-switch-break/&quot; style=&quot;background: transparent; border-bottom-color: rgb(19, 78, 139); border-bottom-style: dotted; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #134e8b; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;&quot;&gt;part 13 of this course&lt;/a&gt;, the Serial Monitor window has only been used for output purposes. It was used to display the results or outputs from various example sketches in each part of the course. Let&#39;s now look at how to handle both serial input and output.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Getting Serial Input&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The following sketch shows how to get a single character from the Serial Monitor window and determine if the character is a number or not.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 653.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
}

&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;char&lt;/span&gt; rx_byte = 0;

&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;available&lt;/span&gt;() &amp;gt; 0) {    &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// is a character available?&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rx_byte&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;read&lt;/span&gt;();       &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// get the character&lt;/span&gt;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// check if a number was received&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; ((rx_byte &amp;gt;= &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;0&#39;&lt;/span&gt;) &amp;amp;&amp;amp; (rx_byte &amp;lt;= &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;9&#39;&lt;/span&gt;)) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Number received: &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(rx_byte);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/span&gt; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Not a number.&quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;}&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// end: if (Serial.available() &amp;gt; 0)&lt;/span&gt;
}
&lt;/pre&gt;
&lt;div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
How the Sketch Works&lt;/h3&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Checking for a Character&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In the Arduino main loop (&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop()&lt;/b&gt;&amp;nbsp;function), an&amp;nbsp;&lt;i style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/i&gt;&amp;nbsp;statement is used to check if a character is available on the serial port – i.e. if a character has been sent from the Serial Monitor window and received by the Arduino.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
This&amp;nbsp;&lt;i style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/i&gt;&amp;nbsp;statement is run as fast as it takes to run the&amp;nbsp;&lt;i style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/i&gt;&amp;nbsp;statement and get back to the top of the loop to run it again.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;available&lt;/span&gt;() &amp;gt; 0) {    &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// is a character available?&lt;/span&gt;
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Nothing in the body of the&amp;nbsp;&lt;i style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/i&gt;&amp;nbsp;statement is run until a character is received.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Getting a Character&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
When a character is received on the serial port, it is stored in a character variable (of type&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;char&lt;/b&gt;) called&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;rx_byte&lt;/b&gt;.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;rx_byte&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;read&lt;/span&gt;();       &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// get the character&lt;/span&gt;
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
A copy of the received character is now stored in the&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;rx_byte&lt;/b&gt;&amp;nbsp;variable and we can use the received character in our sketch.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Check if the Received Character is a Number&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The sketch tests whether the received character is a number or not by checking if the character is greater than or equal to &#39;0&#39; and less than or equal to &#39;9&#39;.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; ((rx_byte &amp;gt;= &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;0&#39;&lt;/span&gt;) &amp;amp;&amp;amp; (rx_byte &amp;lt;= &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;9&#39;&lt;/span&gt;)) {
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
We are actually checking for the character numbers &#39;0&#39; to &#39;9&#39; and not the actual integer numbers 0 to 9. This is because the data received from the Serial Monitor window is in&amp;nbsp;&lt;a class=&quot;targetblank&quot; href=&quot;https://en.wikipedia.org/wiki/ASCII&quot; style=&quot;background: transparent; border-bottom-color: rgb(19, 78, 139); border-bottom-style: dotted; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #134e8b; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;&quot; target=&quot;_blank&quot;&gt;ASCII format&lt;/a&gt;.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
From the&amp;nbsp;&lt;a class=&quot;targetblank&quot; href=&quot;https://en.wikipedia.org/wiki/ASCII#ASCII_printable_code_chart&quot; style=&quot;background: transparent; border-bottom-color: rgb(19, 78, 139); border-bottom-style: dotted; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #134e8b; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;&quot; target=&quot;_blank&quot;&gt;table that shows the printable ASCII characters&lt;/a&gt;, we can see that the ASCII character &#39;0&#39; has the integer value of 48 decimal and the ASCII character &#39;9&#39; has the decimal value of 57. In other words when &#39;0&#39; is typed on the keyboard in the Serial Monitor window &quot;send&quot; field and the&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Send&lt;/b&gt;&amp;nbsp;button is clicked, the integer value of 48 is sent to the Arduino. In the sketch, we can refer to this character as &#39;0&#39; or 48.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The same&amp;nbsp;&lt;i style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/i&gt;&amp;nbsp;statement could be written using decimal integers as follows:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; ((rx_byte &amp;gt;= &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;48&lt;/span&gt;) &amp;amp;&amp;amp; (rx_byte &amp;lt;= &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;57&lt;/span&gt;)) {
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
This code would do exactly the same as the version that checks for the characters.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
If the character received is one of the number characters, the number character will be printed out. The&amp;nbsp;&lt;i style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/i&gt;&amp;nbsp;statement takes care of any character that is not a number character.&lt;/div&gt;
&lt;div class=&quot;clr_flt&quot; style=&quot;background: rgb(255, 255, 255); border: 0px; clear: both; font-family: arial, helvetica, verdana, sans-serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Getting String Input&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The previous sketch was used to get and process a single character at a time. It will be more useful if we could get a whole string at a time, then we could get a name as input, or a number that is more than one digit long.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Finding the End of a String&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
A string is a series of characters. To be able to read a string from the serial port in the Arduino, we will need to know when the string ends. One way to do this is to insert a newline character at the end of the string. A newline character is a non-printable ASCII character that is called &quot;line feed&quot; in the&amp;nbsp;&lt;a class=&quot;targetblank&quot; href=&quot;https://en.wikipedia.org/wiki/ASCII#ASCII_control_code_chart&quot; style=&quot;background: transparent; border-bottom-color: rgb(19, 78, 139); border-bottom-style: dotted; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #134e8b; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;&quot; target=&quot;_blank&quot;&gt;ASCII control code table&lt;/a&gt;.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The linefeed character has a value of 10 decimal but can be written as an escape code in an Arduino sketch as: &#39;\n&#39;.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The following sketch is a modified version of the previous sketch. In addition to checking whether a number or non-number is received, it also checks whether the newline character is received.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
When the sketch is run and a character is sent from the Serial Monitor window, a setting at the bottom of the Serial Monitor window must be changed so that a newline character is appended to the character sent as shown in the image below the sketch.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 653.406px;&quot;&gt;x_byte &amp;lt;= &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;9&#39;&lt;/span&gt;)) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Number received: &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(rx_byte);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (rx_byte == &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;\n&#39;&lt;/span&gt;) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Newline&quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/span&gt; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Not a number.&quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 653.406px;&quot;&gt;&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 653.406px;&quot;&gt;}
&amp;nbsp;&amp;nbsp;}&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// end: if (Serial.available() &amp;gt; 0)&lt;/span&gt;
}
&lt;/pre&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe width=&quot;320&quot; height=&quot;266&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/ww-3uQThkK8/0.jpg&quot; src=&quot;https://www.youtube.com/embed/ww-3uQThkK8?feature=player_embedded&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
How the Sketch Works&lt;/h3&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Checking for a Character&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
In the Arduino main loop (&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop()&lt;/b&gt;&amp;nbsp;function), an&amp;nbsp;&lt;i style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/i&gt;&amp;nbsp;statement is used to check if a character is available on the serial port – i.e. if a character has been sent from the Serial Monitor window and received by the Arduino.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
This&amp;nbsp;&lt;i style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/i&gt;&amp;nbsp;statement is run as fast as it takes to run the&amp;nbsp;&lt;i style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/i&gt;&amp;nbsp;statement and get back to the top of the loop to run it again.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;available&lt;/span&gt;() &amp;gt; 0) {    &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// is a character available?&lt;/span&gt;
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Nothing in the body of the&amp;nbsp;&lt;i style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/i&gt;&amp;nbsp;statement is run until a character is received.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Getting a Character&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
When a character is received on the serial port, it is stored in a character variable (of type&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;char&lt;/b&gt;) called&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;rx_byte&lt;/b&gt;.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;rx_byte&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;read&lt;/span&gt;();       &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// get the character&lt;/span&gt;
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
A copy of the received character is now stored in the&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;rx_byte&lt;/b&gt;&amp;nbsp;variable and we can use the received character in our sketch.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Check if the Received Character is a Number&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The sketch tests whether the received character is a number or not by checking if the character is greater than or equal to &#39;0&#39; and less than or equal to &#39;9&#39;.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; ((rx_byte &amp;gt;= &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;0&#39;&lt;/span&gt;) &amp;amp;&amp;amp; (rx_byte &amp;lt;= &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;9&#39;&lt;/span&gt;)) {
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
We are actually checking for the character numbers &#39;0&#39; to &#39;9&#39; and not the actual integer numbers 0 to 9. This is because the data received from the Serial Monitor window is in&amp;nbsp;&lt;a class=&quot;targetblank&quot; href=&quot;https://en.wikipedia.org/wiki/ASCII&quot; style=&quot;background: transparent; border-bottom-color: rgb(19, 78, 139); border-bottom-style: dotted; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #134e8b; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;&quot; target=&quot;_blank&quot;&gt;ASCII format&lt;/a&gt;.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
From the&amp;nbsp;&lt;a class=&quot;targetblank&quot; href=&quot;https://en.wikipedia.org/wiki/ASCII#ASCII_printable_code_chart&quot; style=&quot;background: transparent; border-bottom-color: rgb(19, 78, 139); border-bottom-style: dotted; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #134e8b; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;&quot; target=&quot;_blank&quot;&gt;table that shows the printable ASCII characters&lt;/a&gt;, we can see that the ASCII character &#39;0&#39; has the integer value of 48 decimal and the ASCII character &#39;9&#39; has the decimal value of 57. In other words when &#39;0&#39; is typed on the keyboard in the Serial Monitor window &quot;send&quot; field and the&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Send&lt;/b&gt;&amp;nbsp;button is clicked, the integer value of 48 is sent to the Arduino. In the sketch, we can refer to this character as &#39;0&#39; or 48.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The same&amp;nbsp;&lt;i style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/i&gt;&amp;nbsp;statement could be written using decimal integers as follows:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; ((rx_byte &amp;gt;= &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;48&lt;/span&gt;) &amp;amp;&amp;amp; (rx_byte &amp;lt;= &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;57&lt;/span&gt;)) {
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
This code would do exactly the same as the version that checks for the characters.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
If the character received is one of the number characters, the number character will be printed out. The&amp;nbsp;&lt;i style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/i&gt;&amp;nbsp;statement takes care of any character that is not a number character.&lt;/div&gt;
&lt;div class=&quot;clr_flt&quot; style=&quot;background: rgb(255, 255, 255); border: 0px; clear: both; font-family: arial, helvetica, verdana, sans-serif; font-size: 16px; font-weight: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Getting String Input&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The previous sketch was used to get and process a single character at a time. It will be more useful if we could get a whole string at a time, then we could get a name as input, or a number that is more than one digit long.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Finding the End of a String&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
A string is a series of characters. To be able to read a string from the serial port in the Arduino, we will need to know when the string ends. One way to do this is to insert a newline character at the end of the string. A newline character is a non-printable ASCII character that is called &quot;line feed&quot; in the&amp;nbsp;&lt;a class=&quot;targetblank&quot; href=&quot;https://en.wikipedia.org/wiki/ASCII#ASCII_control_code_chart&quot; style=&quot;background: transparent; border-bottom-color: rgb(19, 78, 139); border-bottom-style: dotted; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #134e8b; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;&quot; target=&quot;_blank&quot;&gt;ASCII control code table&lt;/a&gt;.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The linefeed character has a value of 10 decimal but can be written as an escape code in an Arduino sketch as: &#39;\n&#39;.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The following sketch is a modified version of the previous sketch. In addition to checking whether a number or non-number is received, it also checks whether the newline character is received.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
When the sketch is run and a character is sent from the Serial Monitor window, a setting at the bottom of the Serial Monitor window must be changed so that a newline character is appended to the character sent as shown in the image below the sketch.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 651.528px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
}

&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;char&lt;/span&gt; rx_byte = 0;

&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;available&lt;/span&gt;() &amp;gt; 0) {    &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// is a character available?&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rx_byte&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;read&lt;/span&gt;();       &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// get the character&lt;/span&gt;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// check if a number was received&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; ((rx_byte &amp;gt;= &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;0&#39;&lt;/span&gt;) &amp;amp;&amp;amp; (rx_byte &amp;lt;= &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;9&#39;&lt;/span&gt;)) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Number received: &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(rx_byte);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (rx_byte == &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;\n&#39;&lt;/span&gt;) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Newline&quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/span&gt; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Not a number.&quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/pre&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 651.528px;&quot;&gt;}&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// end: if (Serial.available() &amp;gt; 0)&lt;/span&gt;
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe width=&quot;320&quot; height=&quot;266&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/wyGbPZYWx54/0.jpg&quot; src=&quot;https://www.youtube.com/embed/wyGbPZYWx54?feature=player_embedded&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Before running the sketch, make sure that the Arduino Serial Monitor window is set to &quot;Newline&quot; as shown in this image.&lt;/div&gt;
&lt;img alt=&quot;Setting the newline character in the Arduino Serial Monitor window&quot; height=&quot;257&quot; src=&quot;https://startingelectronics.org/software/arduino/learn-to-program-course/19-serial-input/serial-monitor-newline.png&quot; style=&quot;background: rgb(255, 255, 255); border: 0px; font-family: arial, helvetica, verdana, sans-serif; font-size: 16px; font-weight: normal; height: auto; margin: 0px; max-width: 100%; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot; width=&quot;458&quot; /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
When &quot;Newline&quot; is set in the Serial Monitor window, whatever is typed into the &quot;send&quot; field of the Serial Monitor window, will be followed by a newline character.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
An&amp;nbsp;&lt;i style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else if&lt;/i&gt;&amp;nbsp;is used to test if a newline character has been received as shown in this line of code.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.417px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (rx_byte == &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;\n&#39;&lt;/span&gt;) {
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
This code checks for the newline character which is represented by &#39;\n&#39; and prints &quot;Newline&quot; to the Serial Monitor window if found.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Reading a String&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The sketch below reads a string into the Arduino and uses the newline character to determine when the string ends.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 651.528px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Enter your name.&quot;&lt;/span&gt;);
}

&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;char&lt;/span&gt; rx_byte = 0;
&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;String&lt;/span&gt; rx_str = &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;&quot;&lt;/span&gt;;

&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;available&lt;/span&gt;() &amp;gt; 0) {    &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// is a character available?&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rx_byte&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;read&lt;/span&gt;();       &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// get the character&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (rx_byte != &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;\n&#39;&lt;/span&gt;) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// a character of the string was received&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rx_str&amp;nbsp;+=&amp;nbsp;rx_byte;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/span&gt; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// end of string&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Welcome &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(rx_str);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rx_str&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;&quot;&lt;/span&gt;;                &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// clear the string for reuse&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 651.528px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// end: if (Serial.available() &amp;gt; 0)&lt;/span&gt;&lt;/pre&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe width=&quot;320&quot; height=&quot;266&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/643IMZudb3M/0.jpg&quot; src=&quot;https://www.youtube.com/embed/643IMZudb3M?feature=player_embedded&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 651.528px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Each individual character of the string is obtained in the same way as the previous sketches and stored in the&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;rx_byte&lt;/b&gt;&amp;nbsp;variable.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
If the character is not equal to the newline character, then it is added to the&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;String&lt;/b&gt;&amp;nbsp;object&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;rx_str&lt;/b&gt;.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; color: black; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.417px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (rx_byte != &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;\n&#39;&lt;/span&gt;) {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// a character of the string was received&lt;/span&gt;
&amp;nbsp;&amp;nbsp;rx_str&amp;nbsp;+=&amp;nbsp;rx_byte;
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The line of code&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;rx_str&amp;nbsp;+=&amp;nbsp;rx_byte;&lt;/b&gt;&amp;nbsp;is the same as:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; color: black; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.417px;&quot;&gt;rx_str&amp;nbsp;=&amp;nbsp;rx_str&amp;nbsp;+&amp;nbsp;rx_byte;
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
It simply puts each character onto the end of the string to build up the string from received characters.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
After the string has been assembled, the newline character will be received which will then trigger the&amp;nbsp;&lt;i style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/i&gt;&amp;nbsp;statement and the received string is printed out to the Serial Monitor window as part of a welcome message.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Getting a Number&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
When a number is received from the Serial Monitor window, it is a string of number characters and must be converted into a number that can be stored in a number variable such as an integer or&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/b&gt;.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The following sketch checks to see that the received characters are number characters and then converts the number to an integer.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; color: black; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 651.528px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;oid&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background: transparent; border: 0px; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/b&gt;&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background: transparent; border: 0px; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/b&gt;&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background: transparent; border: 0px; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/b&gt;&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Enter a number to multiply by 2.&quot;&lt;/span&gt;);
}

&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;char&lt;/span&gt; rx_byte = 0;
&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;String&lt;/span&gt; rx_str = &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;&quot;&lt;/span&gt;;
&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;boolean&lt;/span&gt; not_number = &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;false&lt;/span&gt;;
&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; result;

&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background: transparent; border: 0px; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/b&gt;&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background: transparent; border: 0px; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/b&gt;&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;available&lt;/span&gt;() &amp;gt; 0) {    &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// is a character available?&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rx_byte&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background: transparent; border: 0px; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/b&gt;&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;read&lt;/span&gt;();       &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// get the character&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; ((rx_byte &amp;gt;= &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;0&#39;&lt;/span&gt;) &amp;amp;&amp;amp; (rx_byte &amp;lt;= &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;9&#39;&lt;/span&gt;)) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rx_str&amp;nbsp;+=&amp;nbsp;rx_byte;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (rx_byte == &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;\n&#39;&lt;/span&gt;) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// end of string&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (not_number) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background: transparent; border: 0px; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/b&gt;&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Not a number&quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/pre&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; color: black; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 651.528px;&quot;&gt;&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 651.528px;&quot;&gt;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/span&gt; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// multiply the number by 2&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;result&amp;nbsp;=&amp;nbsp;rx_str.toInt()&amp;nbsp;*&amp;nbsp;2;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// print the result&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(rx_str);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot; x 2 = &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(result);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;&quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Enter a number to multiply by 2.&quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;not_number&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;false&lt;/span&gt;;         &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// reset flag&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rx_str&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;&quot;&lt;/span&gt;;                &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// clear the string for reuse&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/span&gt; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// non-number character received&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;not_number&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;true&lt;/span&gt;;    &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// flag a non-number&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;}&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// end: if (Serial.available() &amp;gt; 0)&lt;/span&gt;
}&lt;/pre&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe width=&quot;320&quot; height=&quot;266&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/NFNUqf1oeXw/0.jpg&quot; src=&quot;https://www.youtube.com/embed/NFNUqf1oeXw?feature=player_embedded&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 651.528px;&quot;&gt;&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Building the String&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
A string is built up of received characters as done in the previous sketch. If any character received is not a character number, the variable&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;not_number&lt;/b&gt;&amp;nbsp;is set to true to &quot;flag&quot; that a non-number character was received.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Using a Boolean Flag&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;not_number&lt;/b&gt;&amp;nbsp;variable is of type&amp;nbsp;&lt;a class=&quot;targetblank&quot; href=&quot;http://arduino.cc/en/Reference/BooleanVariables&quot; style=&quot;background: transparent; border-bottom-color: rgb(19, 78, 139); border-bottom-style: dotted; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #134e8b; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;&quot; target=&quot;_blank&quot;&gt;boolean&lt;/a&gt;&amp;nbsp;which can only have a value of&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;true&lt;/b&gt;&amp;nbsp;or&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;false&lt;/b&gt;. In the sketch, this variable is used as a flag which is checked later to see if any non-number characters were received.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
After receiving the full string, which occurs when the newline character is received, the&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;not_number&lt;/b&gt;&amp;nbsp;flag is checked and a message is displayed if any character received was not a number.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Processing the String&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
If all the received characters were numbers, the string is converted to an integer using&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;rx_str.&lt;a class=&quot;targetblank&quot; href=&quot;http://arduino.cc/en/Reference/StringToInt&quot; style=&quot;background: transparent; border-bottom-color: rgb(19, 78, 139); border-bottom-style: dotted; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #134e8b; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;&quot; target=&quot;_blank&quot;&gt;toInt()&lt;/a&gt;&lt;/b&gt;, multiplied by 2 and the result stored in the&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;result&lt;/b&gt;&amp;nbsp;variable. The result of the calculation in then printed to the Serial Monitor Window.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Sketch Limitations&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
There are some limitations with this sketch. We cannot get a result when a negative number is sent to the Arduino because the minus sign will trigger the&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;not_number&lt;/b&gt;&amp;nbsp;flag. The size of the number that can be multiplied is also limited by the size of a positive integer on the Arduino.&lt;/div&gt;
&lt;/pre&gt;
&lt;/pre&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://moroccoele.blogspot.com/feeds/200089233620006666/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2535795214191795882/200089233620006666' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/200089233620006666'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/200089233620006666'/><link rel='alternate' type='text/html' href='http://moroccoele.blogspot.com/2017/03/getting-and-using-arduino-serial-input.html' title='Getting and Using Arduino Serial Input'/><author><name>zouhair</name><uri>http://www.blogger.com/profile/03215618839043737171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/ww-3uQThkK8/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2535795214191795882.post-1340897218895732186</id><published>2017-03-01T07:28:00.002-08:00</published><updated>2017-03-01T07:28:33.822-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Arduino"/><title type='text'>Arduino Strings</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Strings are used to store text. They can be used to display text on an LCD or in the Arduino IDE Serial Monitor window.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Strings are also useful for storing user input – for example the characters that a user types on a keypad connected to the Arduino.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
There are two types of strings in Arduino programming:&lt;br /&gt;1) Arrays of characters which are the same as the strings used in C programming&lt;br /&gt;2) The Arduino&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;String&lt;/b&gt;&amp;nbsp;which lets us use a string object in a sketch&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Strings, objects and how to use strings in Arduino sketches are fully explained in this part of the Arduino programming course. The question of which type of sting to use in a sketch is answered at the end of this article.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
String Character Arrays&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The first type of string that we will look at is the string that is a series of characters of type&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;char&lt;/b&gt;. The previous part of this course showed&amp;nbsp;&lt;a href=&quot;https://startingelectronics.org/software/arduino/learn-to-program-course/17-arrays/&quot; style=&quot;background: transparent; border-bottom-color: rgb(19, 78, 139); border-bottom-style: dotted; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #134e8b; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;&quot;&gt;what an array is&lt;/a&gt;&amp;nbsp;– a consecutive series of the same type of variable stored in memory. A string is an array of&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;char&lt;/b&gt;&amp;nbsp;variables.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
A string is a special array that has one extra element at the end of the string which always has the value of 0 (zero). This is known as a &quot;null terminated string&quot;.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
String Character Array Example Sketch&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
This sketch will show how to make a string and print it to the serial monitor window.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;char&lt;/span&gt; my_str[6];    &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// an array big enough for a 5 character string&lt;/span&gt;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;my_str[0]&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;H&#39;&lt;/span&gt;;  &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// the string consists of 5 characters&lt;/span&gt;
&amp;nbsp;&amp;nbsp;my_str[1]&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;e&#39;&lt;/span&gt;;
&amp;nbsp;&amp;nbsp;my_str[2]&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;l&#39;&lt;/span&gt;;
&amp;nbsp;&amp;nbsp;my_str[3]&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;l&#39;&lt;/span&gt;;
&amp;nbsp;&amp;nbsp;my_str[4]&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;o&#39;&lt;/span&gt;;
&amp;nbsp;&amp;nbsp;my_str[5]&amp;nbsp;=&amp;nbsp;0;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// 6th array element is a null terminator&lt;/span&gt;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(my_str);
}

&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
}

&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The sketch shows what a string is made up of – it consists of a character array with printable characters and a 0 in the last element of the array to show that this is where the string ends.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The string can be printed out to the Arduino IDE Serial Monitor window by using&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial.println()&lt;/b&gt;&amp;nbsp;and passing it the name of the string.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
This same sketch can be written more conveniently this way:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;char&lt;/span&gt; my_str[] = &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Hello&quot;&lt;/span&gt;;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(my_str);
}

&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
}

&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In this sketch, the compiler calculates the size of the string array and also automatically null terminates the string with a zero. An array that is six elements long and consists of five characters followed by a zero is created exactly the same way as in the previous sketch.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Strings and Characters&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Characters are written between single quotes like this:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&#39;w&#39;
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Strings are written between double quotes like this:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&quot;This is a string&quot;
&lt;/pre&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Manipulating String Arrays&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
We can alter a string array within a sketch as the following sketch shows.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 653.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;oid&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;char&lt;/span&gt; like[] = &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;I like coffee and cake&quot;&lt;/span&gt;;  &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// create a string&lt;/span&gt;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// (1) print the string&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(like);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// (2) delete part of the string&lt;/span&gt;
&amp;nbsp;&amp;nbsp;like[13]&amp;nbsp;=&amp;nbsp;0;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(like);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// (3) substitute a word into the string&lt;/span&gt;
&amp;nbsp;&amp;nbsp;like[13]&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39; &#39;&lt;/span&gt;;  &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// replace the null terminator with a space&lt;/span&gt;
&amp;nbsp;&amp;nbsp;like[18]&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;t&#39;&lt;/span&gt;;  &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// insert the new word&lt;/span&gt;
&amp;nbsp;&amp;nbsp;like[19]&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;e&#39;&lt;/span&gt;;
&amp;nbsp;&amp;nbsp;like[20]&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;a&#39;&lt;/span&gt;;
&amp;nbsp;&amp;nbsp;like[21]&amp;nbsp;=&amp;nbsp;0;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// terminate the string&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(like);&lt;/pre&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 653.406px;&quot;&gt;&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 653.406px;&quot;&gt;}

&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
}&lt;/pre&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 653.406px;&quot;&gt;&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Creating and Printing the String&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
In this sketch, a new string is created and then printed for display in the Serial Monitor window (1).&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Shortening the String&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The string is shortened by replacing the 14th character in the string with a null terminating zero (2). This is element number 13 in the string array counting from 0.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
When the string is printed out, all the characters are printed up to the new null terminating zero. The other characters do not disappear – they still exist in memory and the string array is still the same size. The only difference is that any function that works with strings will only see the string up to the first null terminator.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Changing a Word in the String&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Finally the sketch replaces the word &quot;cake&quot; with &quot;tea&quot; (3). It first has to replace the null terminator at&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;like[13]&lt;/b&gt;&amp;nbsp;with a space so that the string is restored to how it was originally created.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
New characters overwrite &quot;cak&quot; of the work &quot;cake&quot; with the word &quot;tea&quot;. This is done by overwriting individual characters. The &#39;e&#39; of &quot;cake&quot; is replaced with a new null terminating character. The result is that the string is actually terminated with two null characters – the original one at the end of the string and the new one that replaces the &#39;e&#39; in &quot;cake&quot;. This makes no difference when the new string is printed out because the function that prints the string stops printing string characters when it encounters the first null terminator.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Functions to Manipulate String Arrays&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The previous sketch manipulated the string in a very manual way by accessing individual characters in the string. To make it easier to manipulate string arrays, you could write your own functions to do so, or use some of the string functions from the C language library.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The next sketch uses some C string functions.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 653.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;char&lt;/span&gt; str[] = &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;This is my string&quot;&lt;/span&gt;;  &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// create a string&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;char&lt;/span&gt; out_str[40];                  &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// output from string functions placed here&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; num;                           &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// general purpose integer&lt;/span&gt;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// (1) print the string&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(str);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// (2) get the length of the string (excludes null terminator)&lt;/span&gt;
&amp;nbsp;&amp;nbsp;num&amp;nbsp;=&amp;nbsp;strlen(str);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;String length is: &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(num);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// (3) get the length of the array (includes null terminator)&lt;/span&gt;
&amp;nbsp;&amp;nbsp;num&amp;nbsp;=&amp;nbsp;sizeof(str);&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// sizeof() is not a C string function&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Size of the array: &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(num);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// (4) copy a string&lt;/span&gt;
&amp;nbsp;&amp;nbsp;strcpy(out_str,&amp;nbsp;str);&lt;/pre&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 653.406px;&quot;&gt;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(out_str);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// (5) add a string to the end of a string (append)&lt;/span&gt;
&amp;nbsp;&amp;nbsp;strcat(out_str,&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot; sketch.&quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(out_str);
&amp;nbsp;&amp;nbsp;num&amp;nbsp;=&amp;nbsp;strlen(out_str);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;String length is: &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(num);
&amp;nbsp;&amp;nbsp;num&amp;nbsp;=&amp;nbsp;sizeof(out_str);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Size of the array out_str[]: &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(num);
}

&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
}
&lt;/pre&gt;
&lt;div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The sketch works in the following way.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
(1) Print the String&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The newly created string is printed to the Serial Monitor window as done in previous sketches.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
(2) Get the Length of the String&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;strlen()&lt;/b&gt;&amp;nbsp;function is used to get the length of the string. The length of the string is for the printable characters only and does not include the null terminator.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The string contains 17 characters, so we see 17 printed in the Serial Monitor window.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
(3) Get the Length of the Array&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The operator&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;sizeof()&lt;/b&gt;&amp;nbsp;is used to get the length of the array that contains the string. The length includes the null terminator, so the length is one more than the length of the string.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;sizeof()&lt;/b&gt;&amp;nbsp;looks like a function, but technically is an operator. It is not part of the C string library, but was used in the sketch to show the difference between the size of the array and the size of the string (or string length).&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
(4) Copy a String&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;strcpy()&lt;/b&gt;&amp;nbsp;function is used to copy the&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;str[]&lt;/b&gt;&amp;nbsp;string to the&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;out_num[]&lt;/b&gt;&amp;nbsp;array. The&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;strcpy()&lt;/b&gt;&amp;nbsp;function copies the second string passed to it into the first string. A copy of the string now exists in the&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;out_num[]&lt;/b&gt;&amp;nbsp;array, but only takes up 18 elements of the array, so we still have 22 free&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;char&lt;/b&gt;&amp;nbsp;elements in the array. These free elements are found after the string in memory.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The string was copied to the array so that we would have some extra space in the array to use in the next part of the sketch which is adding a string to the end of a string.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
(5) Append a String to a String (Concatenate)&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The sketch joins one string to another, which is known as concatenation. This is done using the&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;strcat()&lt;/b&gt;&amp;nbsp;function. The&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;strcat()&lt;/b&gt;&amp;nbsp;function puts the second string passed to it onto the end of the first string passed to it.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
After concatenation, the length of the string is printed to show the new string length. The length of the array is then printed to show that we have a 25 character long string in a 40 element long array.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Remember that the 25 character long string actually takes up 26 characters of the array because of the null terminating zero.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Array Bounds&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
When working with strings and arrays, it is very important to work within the bounds of the string or array. In the example sketch an array was created that was 40 characters long in order to allocate memory that could be used to manipulate strings.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
If the array was made too small and we tried to copy a string that is bigger than the array to it, the string would be copied over the end of the array. The memory beyond the end of the array could contain other important data used in the sketch which would then be overwritten by our string. If the memory beyond the end of the string is overrun, it could crash the sketch or cause unexpected behaviour.&lt;/div&gt;
&lt;div class=&quot;clr_flt&quot; style=&quot;background: rgb(255, 255, 255); border: 0px; clear: both; font-family: arial, helvetica, verdana, sans-serif; font-size: 16px; font-weight: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The Arduino String Object&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The second type of string used in Arduino programming is the&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;String&lt;/b&gt;&amp;nbsp;object.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
What is an Object?&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
An object is a construct that contains both data and functions. A&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;String&lt;/b&gt;&amp;nbsp;object can be created just like a variable and assigned a value or string. The&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;String&lt;/b&gt;&amp;nbsp;object contains functions (which are called &quot;methods&quot; in object oriented programming (OOP)) which operate on the string data contained in the&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;String&lt;/b&gt;&amp;nbsp;object.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The following sketch and explanation will make it clearer what an object is and how the&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;String&lt;/b&gt;&amp;nbsp;object is used.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 653.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;String&lt;/span&gt; my_str = &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;This is my string.&quot;&lt;/span&gt;;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// (1) print the string&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(my_str);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// (2) change the string to upper-case&lt;/span&gt;
&amp;nbsp;&amp;nbsp;my_str.toUpperCase();
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(my_str);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// (3) overwrite the string&lt;/span&gt;
&amp;nbsp;&amp;nbsp;my_str&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;My new string.&quot;&lt;/span&gt;;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(my_str);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// (4) replace a word in the string&lt;/span&gt;
&amp;nbsp;&amp;nbsp;my_str.replace(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;string&quot;&lt;/span&gt;, &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Arduino sketch&quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(my_str);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// (5) get the length of the string&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 653.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; color: black; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 653.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;String length is: &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(my_str.length());
}

&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
}
&lt;/pre&gt;
&lt;div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
A string object is created and assigned a value (or string) at the top of the sketch.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; color: black; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;String&lt;/span&gt; my_str = &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;This is my string.&quot;&lt;/span&gt;;
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
This creates a&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;String&lt;/b&gt;&amp;nbsp;object with the name&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;my_str&lt;/b&gt;&amp;nbsp;and gives it a value of &quot;This is my string.&quot;.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
This can be compared to creating a variable and assigning a value to it such as an integer:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; color: black; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; my_var = 102;
&lt;/pre&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
(1) Printing the String&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The string can be printed to the Serial Monitor window just like a character array string.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
(2) Convert the String to Upper-case&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The string object&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;my_str&lt;/b&gt;&amp;nbsp;that was created has a number of functions or methods that can operated on it. These methods are invoked by using the objects name followed by the dot operator (.) and then the name of the function to use.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; color: black; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;my_str.toUpperCase();
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;toUpperCase()&lt;/b&gt;&amp;nbsp;function operates on the string contained in the&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;my_str&lt;/b&gt;&amp;nbsp;object which is of type&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;String&lt;/b&gt;&amp;nbsp;and converts the string data (or text) that the object contains to upper-case characters.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
A list of the functions that the&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;String&lt;/b&gt;&amp;nbsp;class contains can be found in the&amp;nbsp;&lt;a class=&quot;targetblank&quot; href=&quot;http://arduino.cc/en/Reference/StringObject&quot; style=&quot;background: transparent; border-bottom-color: rgb(19, 78, 139); border-bottom-style: dotted; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #134e8b; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;&quot; target=&quot;_blank&quot;&gt;Arduino String reference&lt;/a&gt;.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Technically&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;String&lt;/b&gt;&amp;nbsp;is called a class and is used to create&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;String&lt;/b&gt;&amp;nbsp;objects.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
(3) Overwrite a String&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The assignment operator is used to assign a new string to the&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;my_str&lt;/b&gt;&amp;nbsp;object that replaces the old string.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; color: black; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;my_str&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;My new string.&quot;&lt;/span&gt;;
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The assignment operator can not be used on character array strings, but works on&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;String&lt;/b&gt;&amp;nbsp;objects only.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
(4) Replacing a Word in the String&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;replace()&lt;/b&gt;&amp;nbsp;function is used to replace the first string passed to it by the second string passed to it.&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;replace()&lt;/b&gt;&amp;nbsp;is another function that is built into the&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;String&lt;/b&gt;&amp;nbsp;class and so is available to use on the&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;String&lt;/b&gt;&amp;nbsp;object&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;my_str&lt;/b&gt;.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
(5) Getting the Length of the String&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Getting the length of the string is easily done by using&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;length()&lt;/b&gt;. In the example sketch, the result returned by&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;length()&lt;/b&gt;&amp;nbsp;is passed directly to&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial.println()&lt;/b&gt;&amp;nbsp;without using an intermediate variable.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
When to use a String Object or String Character Array&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
A&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;String&lt;/b&gt;&amp;nbsp;object is much easier to use than a string character array. The object has built-in functions that can perform a number of operations on strings which are fully documented in the reference section on the Arduino website.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The main disadvantage of using the&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;String&lt;/b&gt;&amp;nbsp;object is that it uses a lot of memory and can quickly use up the Arduinos RAM memory which may cause the Arduino to hang, crash or produce unexpected behaviour.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
If a sketch on an Arduino is small and limits the use of objects, then there should be no problems.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Character array strings are more difficult to use and you may need to write your own functions to operate on these types of strings. The advantage is that you have control of the size of the string arrays that you make, so you can keep the arrays small to save memory.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
You need to make sure that you do not write over the end of the array bounds with string arrays. The&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;String&lt;/b&gt;&amp;nbsp;object does not have this problem and will take care of the string bounds for you, provided that there is enough memory for it to operate on. The&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;String&lt;/b&gt;&amp;nbsp;object can try to write to memory that does not exist when it runs out of memory, but will never write over the end of the string that it is operating on.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Where Strings are Used&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
This part of the Arduino programming course has looked at what strings are, how they look in memory and some operations that can be done on strings.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe width=&quot;320&quot; height=&quot;266&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/5p0qAIv5roE/0.jpg&quot; src=&quot;https://www.youtube.com/embed/5p0qAIv5roE?feature=player_embedded&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Actual practical uses of strings will be covered in the next part of this course when we look at how to get user input from the Serial Monitor window and save the input in a string&lt;/div&gt;
&lt;/div&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 653.406px;&quot;&gt;
&lt;/pre&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 653.406px;&quot;&gt;
&lt;/pre&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://moroccoele.blogspot.com/feeds/1340897218895732186/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2535795214191795882/1340897218895732186' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/1340897218895732186'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/1340897218895732186'/><link rel='alternate' type='text/html' href='http://moroccoele.blogspot.com/2017/03/arduino-strings.html' title='Arduino Strings'/><author><name>zouhair</name><uri>http://www.blogger.com/profile/03215618839043737171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/5p0qAIv5roE/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2535795214191795882.post-3089892643758223006</id><published>2017-03-01T07:20:00.004-08:00</published><updated>2017-03-01T07:20:47.045-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Arduino"/><title type='text'>Arduino Arrays</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Arrays are groups of the same kind of data that are placed consecutively in memory. For example, we can have an array of integers (type&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/b&gt;) which is two or more integer numbers occurring one after the other.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The key here is that each element in an array is placed directly after the previous element which allows us to access each element in turn using a loop.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
An element in an array refers to each value in the array. If we have an array of integers, then each individual integer is referred to as an element of the array. In an array of bytes, each element is a byte (of the Arduino&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;byte&lt;/b&gt;&amp;nbsp;type).&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Using Arrays&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The sketch below shows the basic use of an array.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 653.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; my_array[5];     &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// an array with 5 integer elements&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; i;               &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// used as an index into the array&lt;/span&gt;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;my_array[0]&amp;nbsp;=&amp;nbsp;23;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// assign a value of 23 to the 1st element&lt;/span&gt;
&amp;nbsp;&amp;nbsp;my_array[1]&amp;nbsp;=&amp;nbsp;1001;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// assign a value of 1001 to the 2nd element, etc.&lt;/span&gt;
&amp;nbsp;&amp;nbsp;my_array[2]&amp;nbsp;=&amp;nbsp;9;
&amp;nbsp;&amp;nbsp;my_array[3]&amp;nbsp;=&amp;nbsp;1234;
&amp;nbsp;&amp;nbsp;my_array[4]&amp;nbsp;=&amp;nbsp;987;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// display each number from the array in the serial monitor window&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/span&gt; (i = 0; i &amp;lt; 5; i++) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(my_array[i]);
&amp;nbsp;&amp;nbsp;}
}

&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
}
&lt;/pre&gt;
&lt;div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Defining the Array&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In this sketch, an array of 5 elements is defined. This makes space in memory for 5 integers that are put in the memory one after the other. The values that each element contains after the array is defined can contain any random data – whatever happens to be in the memory at the time. It is also possible that the compiler is set to make the values zero, but we can not rely on this.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Defining an array of 5 integers:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; my_array[5];     &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// an array with 5 integer elements&lt;/span&gt;
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In this example the array is of type&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/b&gt;, but could be a&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;float&lt;/b&gt;,&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;byte&lt;/b&gt;, etc.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The array has a name which is&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;my_array&lt;/b&gt;&amp;nbsp;in the example.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The array has a length&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;[5]&lt;/b&gt;&amp;nbsp;which means that space for 5 consecutive integers is made in memory.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Assigning Values to Elements in the Array&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Each element is assigned an integer value by referencing it using square brackets [] with the number of the element to access in the brackets.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;my_array[0]&amp;nbsp;=&amp;nbsp;23;
my_array[1]&amp;nbsp;=&amp;nbsp;1001;
my_array[2]&amp;nbsp;=&amp;nbsp;9;
my_array[3]&amp;nbsp;=&amp;nbsp;1234;
my_array[4]&amp;nbsp;=&amp;nbsp;987;
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Note that the element numbering starts from zero [0] and not one [1], so the first element in the array is element 0.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In the same way, the last element in the array is numbered one less than the size of the array. In the example, the size of the array is 5, so the number of the last element is 4 – again this is because we are numbering the elements starting with 0.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Accessing an Array in a Loop&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
A&amp;nbsp;&lt;i style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/i&gt;&amp;nbsp;loop is used to get the contents of each element in the array in turn and print the values to the Serial Monitor window.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/span&gt; (i = 0; i &amp;lt; 5; i++) {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(my_array[i]);
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The variable&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i&lt;/b&gt;&amp;nbsp;is used in the&amp;nbsp;&lt;i style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/i&gt;&amp;nbsp;loop as an index into the array to access each element of the array.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In the loop,&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i&lt;/b&gt;&amp;nbsp;is initialized to 0 and then incremented by one each time through the loop so that it counts from 0 to 4. The loop is exited when&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i&lt;/b&gt;&amp;nbsp;becomes 5.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i&lt;/b&gt;&amp;nbsp;variable is used in the array to get the value that the array element is holding starting with element 0 and ending with 4.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;(my_array[i]);
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In the above code snippet, when&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i&lt;/b&gt;&amp;nbsp;is 0, the first element of the array is accessed and we can then get the value that it contains which is 23 in the example sketch.&lt;/div&gt;
&lt;div class=&quot;clr_flt&quot; style=&quot;background: rgb(255, 255, 255); border: 0px; clear: both; font-family: arial, helvetica, verdana, sans-serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
More on Initializing Arrays&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Instead of initializing each element in the array individually, the array can be defined and initialized in one line as shown in this code.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
This sketch does exactly the same as the previous sketch.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; my_array[5] = {23, 1001, 9, 1234, 987};
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; i;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// display each number from the array in the serial monitor window&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/span&gt; (i = 0; i &amp;lt; 5; i++) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(my_array[i]);
&amp;nbsp;&amp;nbsp;}
}

&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
}

&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The values to initialize each element with are placed between braces {} after the assignment operator (the equals sign =). The first value between the braces will be assigned to the first element in the array (element number 0), the second number between braces will be assigned to the second element in the array (element number 1), etc.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The code that does the defining and initializing can also be written without the number of elements in the array between the square brackets:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; my_array[] = {23, 1001, 9, 1234, 987};
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In this case, the compiler will work out how many elements the array must have based on the number of values that are used to initialize it.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Uses of Arrays&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
This part of the course shows that arrays can store data variables of the same type consecutively in memory which allows easy access using a loop.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
There are many uses for arrays in programming, for example, arrays can store data that is being logged, such as temperatures. Strings, which are lines of text, are actually arrays as we will see in the next part of this course.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Actual practical uses of arrays will be shown as the course progresses.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe width=&quot;320&quot; height=&quot;266&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/8UeyqypsaG0/0.jpg&quot; src=&quot;https://www.youtube.com/embed/8UeyqypsaG0?feature=player_embedded&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://moroccoele.blogspot.com/feeds/3089892643758223006/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2535795214191795882/3089892643758223006' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/3089892643758223006'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/3089892643758223006'/><link rel='alternate' type='text/html' href='http://moroccoele.blogspot.com/2017/03/arduino-arrays.html' title='Arduino Arrays'/><author><name>zouhair</name><uri>http://www.blogger.com/profile/03215618839043737171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/8UeyqypsaG0/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2535795214191795882.post-2587546026935250535</id><published>2017-03-01T07:19:00.001-08:00</published><updated>2017-03-01T07:19:11.328-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Arduino"/><title type='text'>Returning a Value from a Function</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In the previous part of this Arduino programming course, we looked at how to pass a value to a function. Now we look at how to get a value back from a function.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Getting a value back from a function is called &quot;returning&quot; the value from the function. The&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;return&lt;/b&gt;&amp;nbsp;keyword is used at the end of the function to get the value back. We must also say what type of value the function is returning, e.g.&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/b&gt;,&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;float&lt;/b&gt;, etc.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The example sketch below uses a function to do a mathematical calculation and then return the result of the calculation which can then be used in the main Arduino sketch.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Function that Returns a Value&lt;/h2&gt;
&lt;div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 653.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;float&lt;/span&gt; area;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// calculate the area of a circle with radius of 9.2&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;area&amp;nbsp;=&amp;nbsp;CircleArea(9.2);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Area of circle is: &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// print area to 4 decimal places&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(area, 4);
}

&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
}

&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;//&amp;nbsp;calculate&amp;nbsp;the&amp;nbsp;area&amp;nbsp;of&amp;nbsp;a&amp;nbsp;circle&lt;/span&gt;
&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;float&lt;/span&gt; CircleArea(&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;float&lt;/span&gt; radius)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;float&lt;/span&gt; result;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;result&amp;nbsp;=&amp;nbsp;3.141592654&amp;nbsp;*&amp;nbsp;radius&amp;nbsp;*&amp;nbsp;radius;&lt;/pre&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 653.406px;&quot;&gt;&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 653.406px;&quot;&gt;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;return&lt;/span&gt; result;
}&lt;/pre&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 653.406px;&quot;&gt;&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
What the Sketch Does&lt;/h3&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
&lt;div style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The sketch calculates the the area of a circle from a radius value of the circle that is hard-coded into the sketch – in the example sketch the value is set to 9.2, but you can set it to any value that you want. The result of the calculation is then sent out of the serial port so that it can be seen in the Arduino IDE Serial Monitor window.&lt;/div&gt;
&lt;div style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The formula for calculating the area of a circle is:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; color: black; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;A = π × r²
OR
A = π × r × r
Where:
A = area of the circle
π = PI = 3.141592654
r = radius of the circle
&lt;/pre&gt;
&lt;div style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In other words, if we know the radius of the circle (radius is the distance from the centre of the circle to the edge) we can calculate the area of the circle.&lt;/div&gt;
&lt;div style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The unit that the radius is in can be any unit that is used to measure distance and the area will be squares of the unit used, e.g. if the radius is in centimetres, the area will be in square centimetres, if the radius is in feet, the result will be in square feet.&lt;/div&gt;
&lt;div style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The video below shows the the sketch running.&lt;/div&gt;
&lt;/h3&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
How the Sketch Works&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;CircleArea()&lt;/b&gt;&amp;nbsp;function must return a value, so is preceded by the type of value that it must return – in this case&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;float&lt;/b&gt;. A&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;float&lt;/b&gt;&amp;nbsp;value called&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;radius&lt;/b&gt;&amp;nbsp;is also passed to the function as explained in the previous part of this course.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;float&lt;/span&gt; CircleArea(&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;float&lt;/span&gt; radius)
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Inside the function body, the radius calculation is done and the result of the calculation is put into the variable&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;result&lt;/b&gt;&amp;nbsp;which is a variable created in the function.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The function then returns the result using the&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;return&lt;/b&gt;&amp;nbsp;keyword at the bottom of the function.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;return&lt;/span&gt; result;
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The formula is translated into code for the Arduino as follows:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;A = π × r × r
Becomes:
result&amp;nbsp;=&amp;nbsp;3.141592654&amp;nbsp;*&amp;nbsp;radius&amp;nbsp;*&amp;nbsp;radius;
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
In the part of the sketch that calls the&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;CircleArea()&lt;/b&gt;&amp;nbsp;function, the function basically becomes the value that it returns and can be assigned to a variable.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The variable&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;area&lt;/b&gt;&amp;nbsp;is assigned the value that the&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;CircleArea()&lt;/b&gt;&amp;nbsp;function returns:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;area&amp;nbsp;=&amp;nbsp;CircleArea(9.2);
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
After this, the result of the calculation, which is the area of the circle, is sent out the serial port to be displayed in the Arduino IDE Serial Monitor window.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
A Shorter Version of the Sketch&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The sketch above can be written in a shorter way without using some of the intermediate variables as shown below.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Area of circle is: &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// print area to 4 decimal places&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(CircleArea(9.2), 4);
}

&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
}

&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;//&amp;nbsp;calculate&amp;nbsp;the&amp;nbsp;area&amp;nbsp;of&amp;nbsp;a&amp;nbsp;circle&lt;/span&gt;
&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;float&lt;/span&gt; CircleArea(&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;float&lt;/span&gt; radius)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;return&lt;/span&gt; (3.141592654 * radius * radius);
}

&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
In this sketch, the&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;CircleArea()&lt;/b&gt;&amp;nbsp;function returns the result of the calculation on one line without first assigning it to a variable.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;return&lt;/span&gt; (3.141592654 * radius * radius);
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
This method of doing the calculation and returning the value is fine, although it may not be as easy to read the code as the first example.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
When the&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;CircleArea()&lt;/b&gt;&amp;nbsp;function is called in the sketch, it is passed to&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial.println()&lt;/b&gt;&amp;nbsp;as if it were a variable. This is possible because when a function returns a variable, it takes on the value of the variable. The sketch therefore works the same way as the first sketch, although again, it is more difficult to read the code.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(CircleArea(9.2), 4);
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The size of the binary output file (the file that gets loaded to the Arduino after compiling) from the Arduino compiler is&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;4,040 bytes&lt;/b&gt;&amp;nbsp;for both sketches in Arduino IDE version 1.0.6.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe width=&quot;320&quot; height=&quot;266&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/2NY0XVUG0Ac/0.jpg&quot; src=&quot;https://www.youtube.com/embed/2NY0XVUG0Ac?feature=player_embedded&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://moroccoele.blogspot.com/feeds/2587546026935250535/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2535795214191795882/2587546026935250535' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/2587546026935250535'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/2587546026935250535'/><link rel='alternate' type='text/html' href='http://moroccoele.blogspot.com/2017/03/returning-value-from-function.html' title='Returning a Value from a Function'/><author><name>zouhair</name><uri>http://www.blogger.com/profile/03215618839043737171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/2NY0XVUG0Ac/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2535795214191795882.post-378981868846997477</id><published>2017-02-24T06:57:00.002-08:00</published><updated>2017-02-24T06:57:54.144-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Arduino"/><title type='text'>Arduino Functions</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
in this part of the Arduino programming course, you will learn how to write your own functions and use them in your sketches. The structure and use of functions is fully explained.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Functions were briefly encountered in&amp;nbsp;&lt;a href=&quot;https://startingelectronics.org/software/arduino/learn-to-program-course/01-program-structure-flow/&quot; style=&quot;background: transparent; border-bottom-color: rgb(19, 78, 139); border-bottom-style: dotted; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #134e8b; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;&quot;&gt;part 1 of this programming course&lt;/a&gt;&amp;nbsp;where some basic facts about functions where stated –&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;1)&lt;/b&gt;&amp;nbsp;each function must have a unique name,&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;2)&lt;/b&gt;&amp;nbsp;the function name is followed by parentheses ()&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;3)&lt;/b&gt;&amp;nbsp;functions have a return type, e.g.&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/b&gt;,&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;4)&lt;/b&gt;&amp;nbsp;the body of a function is enclosed in opening and closing braces {}.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
We will start by examining the structure of a function and then see how to write functions.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
The Structure of a Function&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Before a function can be used in a sketch, it must be created. The following code is an example of a function that was created to print a dashed line in the Arduino IDE.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; DashedLine()
{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;----------------&quot;&lt;/span&gt;);
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The code above that creates the function is called the function definition. The image below shows the components of a function.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinBaNO_VafeQhkqxVyBdxJ46tUCRbtT1fDtltZMVd2Q6F4UicLsMUJayUYj4d5aJF70fbOsK6ebBT5Z-0uvdc24z0ft9jOBlPkDHDVvtSmTrtJ_ueCO-RIA0_ccMxPBI4ER1uzzgGV3NK7/s1600/1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;140&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinBaNO_VafeQhkqxVyBdxJ46tUCRbtT1fDtltZMVd2Q6F4UicLsMUJayUYj4d5aJF70fbOsK6ebBT5Z-0uvdc24z0ft9jOBlPkDHDVvtSmTrtJ_ueCO-RIA0_ccMxPBI4ER1uzzgGV3NK7/s320/1.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
n this part of the Arduino programming course, you will learn how to write your own functions and use them in your sketches. The structure and use of functions is fully explained.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Functions were briefly encountered in&amp;nbsp;&lt;a href=&quot;https://startingelectronics.org/software/arduino/learn-to-program-course/01-program-structure-flow/&quot; style=&quot;background: transparent; border-bottom-color: rgb(19, 78, 139); border-bottom-style: dotted; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #134e8b; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;&quot;&gt;part 1 of this programming course&lt;/a&gt;&amp;nbsp;where some basic facts about functions where stated –&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;1)&lt;/b&gt;&amp;nbsp;each function must have a unique name,&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;2)&lt;/b&gt;&amp;nbsp;the function name is followed by parentheses ()&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;3)&lt;/b&gt;&amp;nbsp;functions have a return type, e.g.&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/b&gt;,&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;4)&lt;/b&gt;&amp;nbsp;the body of a function is enclosed in opening and closing braces {}.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
We will start by examining the structure of a function and then see how to write functions.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
The Structure of a Function&lt;/h2&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Before a function can be used in a sketch, it must be created. The following code is an example of a function that was created to print a dashed line in the Arduino IDE.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; color: black; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; DashedLine()
{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;----------------&quot;&lt;/span&gt;);
}
&lt;/pre&gt;
&lt;div style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The code above that creates the function is called the function definition. The image below shows the components of a function.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAEfvvYJkbLSRBRzzcg7AY1b5QOXTUkHl9_PdPFxDVmsdKTmzitN3LuM7gvvTjevCnBn3nVzBwRJrcY8XQH4kvVY0WZzP81IEs0HZ_Q1XYOlUsrjU6-47J1YDWhlewySRM1tjlGv0lL_GU/s1600/10.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;140&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAEfvvYJkbLSRBRzzcg7AY1b5QOXTUkHl9_PdPFxDVmsdKTmzitN3LuM7gvvTjevCnBn3nVzBwRJrcY8XQH4kvVY0WZzP81IEs0HZ_Q1XYOlUsrjU6-47J1YDWhlewySRM1tjlGv0lL_GU/s320/10.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/h2&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Function Name&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
When we create a function, it must be given a name. The naming convention for functions is the same as for variables:&lt;/div&gt;
&lt;ul style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin: 0px 0px 7px; outline: 0px; overflow: hidden; padding: 0px 0px 0px 1.8em; vertical-align: baseline;&quot;&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;The function name can be made up of alphanumeric characters (A to Z; a to z; 0 to 9) and the underscore (_).&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;The function name may not start with a number i.e. the numbers 0 to 9.&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;A function name must not be used that is the same as a language keyword or existing function.&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The function name ends with parentheses (). Nothing is passed to the example function above, so the parentheses are empty. Passing values or parameters to functions will be explained later in this tutorial.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Return Type&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
A function must have a return type. The example function does not return anything, so has a return type of void. Returning a value from a function will be explained in the next part of this course.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Function Body&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The function body is made up of statements placed between braces {}. The statements make up the functionality of the function (what the function will do when it is called).&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
When a function is used, it is said to be &quot;called&quot;. We will look at how to call a function next.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Calling a Function&lt;/h2&gt;
&lt;div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
To use the function that was created above, it must be called in a sketch as shown in the sketch below.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;DashedLine();
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;| Program Menu |&quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;DashedLine();
}

&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
}

&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; DashedLine()
{
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;----------------&quot;&lt;/span&gt;);
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 15.568px;&quot;&gt;In the sketch above, the&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;DashedLine()&lt;/b&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 15.568px;&quot;&gt;&amp;nbsp;function is created at the bottom of the file and then called twice at the top of the file as shown in the image below.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjTj3DlG-sjzKd9N6WxzRXjHLMAjdVhW4gaBxltKKifyCxT1fJq0Gyc9mbwr_tvyYWNeriEM4738hBzCXYiunAZC9J9dA8qscFL3YJNRXaP-ogTr1zknXQVXmgAzG3M-TmVTssXqf5Lv9b/s1600/11.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;203&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjTj3DlG-sjzKd9N6WxzRXjHLMAjdVhW4gaBxltKKifyCxT1fJq0Gyc9mbwr_tvyYWNeriEM4738hBzCXYiunAZC9J9dA8qscFL3YJNRXaP-ogTr1zknXQVXmgAzG3M-TmVTssXqf5Lv9b/s320/11.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
To call a function, use the function name followed by opening and closing parentheses. Finally terminate the statement that calls the function with a semicolon.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Load the sketch to an Arduino and then open the terminal window. The sketch prints some text in a box as shown below.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;Output from the function&quot; height=&quot;173&quot; src=&quot;https://startingelectronics.org/software/arduino/learn-to-program-course/15-functions/function-output1.png&quot; style=&quot;background: rgb(255, 255, 255); border: 0px; font-family: arial, helvetica, verdana, sans-serif; font-size: 16px; height: auto; margin: 0px; max-width: 100%; outline: 0px; padding: 0px; text-align: start; vertical-align: baseline;&quot; width=&quot;393&quot; /&gt;&lt;/div&gt;
&lt;div class=&quot;pic_caption&quot; style=&quot;background: rgb(255, 255, 255); border: 0px; color: blue; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.8em; font-weight: bold; line-height: 16.64px; margin-bottom: 16px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Output from the DashedLine() Function&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The first time that the function is called, it prints the dashed line shown in the top of the image. Text is then written to the serial monitor window by the statement below the function call. The function is then called again to print the same dashed line that completes the box.&lt;/div&gt;
&lt;div class=&quot;clr_flt&quot; style=&quot;background: rgb(255, 255, 255); border: 0px; clear: both; font-family: arial, helvetica, verdana, sans-serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Why Use Functions&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The function used in the example above is very simple, so all the benefits of using functions will not be seen immediately.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
One advantage of using functions is that they avoid having to write the same code over and over again in a sketch which saves time and memory. Every time that a function is called, we are just reusing code that has been written once.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
If a function needs to be modified, it only has to be done once and the modifications will take effect every place in a sketch that the function is called. If a function was not used, each place that the statements are found in a sketch to do a particular task would need to be located and modified.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Functions can be used to break a sketch up into pieces which make it more modular and easier to understand. Functions can be reused in other sketches.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Passing a Value to a Function&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In the sketch above, the length of the line that the function prints out is fixed in the function. If we change the text that is in the box, it may not fit in the box properly. The function needs to be modified so that we can tell it what size line it must draw.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The above function can be modified to pass a value to it that will tell it how many characters long to make the line that it draws.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The modified sketch is shown below.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 653.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// draw the menu box&lt;/span&gt;
&amp;nbsp;&amp;nbsp;DashedLine(24);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;| Program Options Menu |&quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;DashedLine(24);
}

&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
}

&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; DashedLine(&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; len)
{
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; i;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// draw the line&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/span&gt; (i = 0; i &amp;lt; len; i++) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;-&quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// move the cursor to the next line&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;&quot;&lt;/span&gt;);
}
&lt;/pre&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe width=&quot;320&quot; height=&quot;266&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/HBmrEkqQ4Ds/0.jpg&quot; src=&quot;https://www.youtube.com/embed/HBmrEkqQ4Ds?feature=player_embedded&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;DashedLine()&lt;/b&gt;&amp;nbsp;function in the above sketch is modified so that an integer value can be passed to it. The line needs to be 24 characters long to fit the new menu text into it, so we pass it a value of 24.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;DashedLine(24);&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// passing a value of 24 to the function&lt;/span&gt;
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Of course the function has to be modified to handle the value that is being passed to it:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; DashedLine(&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; len)
{
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; i;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// draw the line&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/span&gt; (i = 0; i &amp;lt; len; i++) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;-&quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// move the cursor to the next line&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;&quot;&lt;/span&gt;);
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The function needs to be able to accept an integer value that is passed to it. The variable type and the name of the variable are inserted between the opening an closing parentheses after the function name.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; DashedLine(&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; len)
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
We can now use the&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;len&lt;/b&gt;&amp;nbsp;integer variable in the body of the&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;DashedLine()&lt;/b&gt;&amp;nbsp;function. The variable will contain whatever value was passed to it when the function was called.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The body of the sketch uses the&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;len&lt;/b&gt;&amp;nbsp;variable in a&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/b&gt;&amp;nbsp;loop to print out the correct number of dashes that make up the dashed line of the menu box.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The cursor is moved to the next line in the serial monitor by calling&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial.println(&quot;&quot;);&lt;/b&gt;&amp;nbsp;with an empty string.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
After the function has run the last statement in its body, it is said to &quot;return&quot;. When a function returns, program execution continues below the statement that called the function – i.e. the statement below the function call is run next.&lt;/div&gt;
&lt;div class=&quot;article_pg_nav&quot; style=&quot;background: rgb(255, 255, 255); border: 0px; font-family: arial, helvetica, verdana, sans-serif; font-size: 16px; margin: 20px 0px; min-height: 70px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;background: transparent; border: 0px; color: #444444; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://moroccoele.blogspot.com/feeds/378981868846997477/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2535795214191795882/378981868846997477' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/378981868846997477'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/378981868846997477'/><link rel='alternate' type='text/html' href='http://moroccoele.blogspot.com/2017/02/arduino-functions.html' title='Arduino Functions'/><author><name>zouhair</name><uri>http://www.blogger.com/profile/03215618839043737171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinBaNO_VafeQhkqxVyBdxJ46tUCRbtT1fDtltZMVd2Q6F4UicLsMUJayUYj4d5aJF70fbOsK6ebBT5Z-0uvdc24z0ft9jOBlPkDHDVvtSmTrtJ_ueCO-RIA0_ccMxPBI4ER1uzzgGV3NK7/s72-c/1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2535795214191795882.post-3969056284834159125</id><published>2017-02-24T06:40:00.001-08:00</published><updated>2017-02-24T06:40:27.496-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Arduino"/><title type='text'>Arduino Conditional Operator</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The&amp;nbsp;&lt;i style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;conditional operator&lt;/i&gt;&amp;nbsp;is another decision making construct in Arduino programming.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The conditional operator consists of a condition, which can evaluate to true or false, and two expressions.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
If the condition evaluates to true, the conditional expression becomes equal to the first expression. If the condition evaluates to false, the expression becomes equal to the second expression.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The rest of this part of the Arduino programming course will explain and illustrate how the conditional operator works.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Structure of the Conditional Operator&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The conditional operator has the following structure:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;condition ? first_expression : second_expression;&lt;/pre&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Where&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;condition&lt;/b&gt;&amp;nbsp;will evaluate to either true or false resulting in the entire expression becoming equal to the first expression (if&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;condition&lt;/b&gt;&amp;nbsp;evaluates to true) or the second expression (if&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;condition&lt;/b&gt;&amp;nbsp;evaluates to false).&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
As can be seen from the above code, the conditional expression consists of a question mark (?) and a colon (:).&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
An example sketch follows to show how to use the conditional expression.&lt;/div&gt;
&lt;div class=&quot;clr_flt&quot; style=&quot;background: rgb(255, 255, 255); border: 0px; clear: both; font-family: arial, helvetica, verdana, sans-serif; font-size: 16px; font-weight: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Conditional Expression Example Sketch&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The sketch below uses the conditional operator to determine which number is the bigger of two numbers.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; val1, val2, result;

&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// change the values of val1 and val2 to see what the&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// conditional expression does&lt;/span&gt;
&amp;nbsp;&amp;nbsp;val1&amp;nbsp;=&amp;nbsp;2;
&amp;nbsp;&amp;nbsp;val2&amp;nbsp;=&amp;nbsp;5;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// if val1 is bigger than val2, return val1&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// else if val1 is less than val2, return val2&lt;/span&gt;
&amp;nbsp;&amp;nbsp;result&amp;nbsp;=&amp;nbsp;(val1&amp;nbsp;&amp;gt;&amp;nbsp;val2)&amp;nbsp;?&amp;nbsp;val1&amp;nbsp;:&amp;nbsp;val2;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// show result in serial monitor window&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;The bigger number is: &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(result);
}

&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
}&lt;/pre&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;Change the value of the variables&amp;nbsp;&lt;b style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;val1&lt;/b&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 15.568px; font-weight: normal; white-space: normal;&quot;&gt;&amp;nbsp;and&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;val2&lt;/b&gt;&lt;span style=&quot;background-color: white; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 15.568px; font-weight: normal; white-space: normal;&quot;&gt;&amp;nbsp;in the sketch, and the bigger of the two numbers will always be displayed in the Serial Monitor window of the Arduino IDE as the video below shows.&lt;/span&gt;&lt;/pre&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe width=&quot;320&quot; height=&quot;266&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/_8NxeafAfGQ/0.jpg&quot; src=&quot;https://www.youtube.com/embed/_8NxeafAfGQ?feature=player_embedded&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
How the Sketch Works&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The condition&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(val1 &amp;gt; val2)&lt;/b&gt;&amp;nbsp;is evaluated and will either evaluate to&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;true&lt;/b&gt;&amp;nbsp;or&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;false&lt;/b&gt;.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The Condition Evaluates to False&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
If val1 is less than val2, the condition evaluates to false. The conditional expression now takes on the value of the second expression – which is val2.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The variable&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;result&lt;/b&gt;&amp;nbsp;is then assigned the value of the expression which is val2 (5 in the sketch) and is the bigger number of the two values val1 and val2.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The Condition Evaluates to True&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
If we change the value of&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;val1&lt;/b&gt;&amp;nbsp;to&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;12&lt;/b&gt;&amp;nbsp;so that we have:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;val1&amp;nbsp;=&amp;nbsp;12;
val2&amp;nbsp;=&amp;nbsp;5;
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;val1&lt;/b&gt;&amp;nbsp;is now bigger than val2 and the condition evaluates to true. The conditional expression takes on the value of the first expression – which is val1.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The variable&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;result&lt;/b&gt;&amp;nbsp;is assigned the value of the expression which is val1. val1 is the bigger of the two values (with a value of 12).&lt;/div&gt;
&lt;/pre&gt;
&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://moroccoele.blogspot.com/feeds/3969056284834159125/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2535795214191795882/3969056284834159125' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/3969056284834159125'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/3969056284834159125'/><link rel='alternate' type='text/html' href='http://moroccoele.blogspot.com/2017/02/arduino-conditional-operator.html' title='Arduino Conditional Operator'/><author><name>zouhair</name><uri>http://www.blogger.com/profile/03215618839043737171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/_8NxeafAfGQ/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2535795214191795882.post-5829810626366032544</id><published>2017-02-13T03:38:00.003-08:00</published><updated>2017-02-13T03:38:37.804-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Arduino"/><title type='text'>Arduino switch and break Statements</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;switch&lt;/em&gt;&amp;nbsp;statement is similar to using&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;with multiple&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else-if&lt;/em&gt;&amp;nbsp;constructs.&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;switch&lt;/em&gt;&amp;nbsp;is used in conjunction with&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;break&lt;/em&gt;&amp;nbsp;which will also be explained in this part of the course.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Using&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;switch&lt;/em&gt;&amp;nbsp;instead of multiple&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else-if&lt;/em&gt;&amp;nbsp;constructs is easier to read and has more flexibility.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;em style=&quot;background: transparent; border: 0px; font-size: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;switch&lt;/em&gt;&amp;nbsp;Statement Example&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The following Arduino sketch shows the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;switch&lt;/em&gt;&amp;nbsp;statement being used in conjunction with the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;break&lt;/em&gt;&amp;nbsp;statement.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Load the sketch to the Arduino and then start the Serial Monitor window. Sending 1 from the serial monitor window to the Arduino will switch the on-board LED on and sending 2 will switch the LED off.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Sending 3 will show the menu of options that the sketch operates on. Sending any other character will bring up a default message showing that the option chosen is invalid.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 653.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;pinMode&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;OUTPUT&lt;/span&gt;);  &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// LED on pin 13 of UNO&lt;/span&gt;
}

&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;char&lt;/span&gt; rx_byte = 0;

&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;available&lt;/span&gt;() &amp;gt; 0) {    &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// is a character available?&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rx_byte&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;read&lt;/span&gt;();
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;switch&lt;/span&gt; (rx_byte) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;case&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;1&#39;&lt;/span&gt;:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;HIGH&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;LED is ON&quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;break&lt;/span&gt;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;case&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;2&#39;&lt;/span&gt;:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;LOW&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;LED is OFF&quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;break&lt;/span&gt;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;case&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;3&#39;&lt;/span&gt;:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;------- MENU -------&quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;1. Switch LED on.&quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;2. Switch LED off.&quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;3. This menu.&quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;--------------------&quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;break&lt;/span&gt;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;default&lt;/span&gt;:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Invalid option&quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;break&lt;/span&gt;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// end: switch (rx_byte)&lt;/span&gt;
&amp;nbsp;&amp;nbsp;}&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// end: if (Serial.available() &amp;gt; 0)&lt;/span&gt;
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
How the sketch works will be explained later on this page, but first we must look at the structure of the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;switch&lt;/em&gt;&amp;nbsp;statement and how the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;break&lt;/em&gt;&amp;nbsp;statement works.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
This video shows the above sketch in operation.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe width=&quot;320&quot; height=&quot;266&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/sqtFs_14Rqw/0.jpg&quot; src=&quot;https://www.youtube.com/embed/sqtFs_14Rqw?feature=player_embedded&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Structure of the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;switch&lt;/em&gt;&amp;nbsp;Statement&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The image below shows the structure of a switch statement.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjN5DIP39SDjo1yzjkhvQv-8z_Ykrm6Tnrb00UFMRMLyY_GBm1hPTplI5EZRW3JC6C91HNcWoX3sHNxMPyr9v3h-XAX5i_aEjSpyN_Bp0sJEuNhN5iklQxgZwHpQj8CLKCVHr7GnUXG4UHA/s1600/4.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;130&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjN5DIP39SDjo1yzjkhvQv-8z_Ykrm6Tnrb00UFMRMLyY_GBm1hPTplI5EZRW3JC6C91HNcWoX3sHNxMPyr9v3h-XAX5i_aEjSpyN_Bp0sJEuNhN5iklQxgZwHpQj8CLKCVHr7GnUXG4UHA/s320/4.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;pic_caption&quot; style=&quot;background: rgb(255, 255, 255); border: 0px; color: blue; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.8em; font-weight: bold; line-height: 16.64px; margin-bottom: 16px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Structure of an Arduino&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;switch&lt;/em&gt;&amp;nbsp;Statement&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;switch&lt;/em&gt;&amp;nbsp;statement has a variable (&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;switch_var&lt;/b&gt;&amp;nbsp;in the above image or&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;rx_byte&lt;/b&gt;&amp;nbsp;in the example sketch) which can be an integer (int) or character (char) variable.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The switch variable will be tested against the value in each&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;case&lt;/em&gt;&amp;nbsp;to see if they match. When a case is found that matches, the statements below the case will be run until the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;break&lt;/em&gt;&amp;nbsp;keyword is reached. This will break the program flow out of the body of the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;switch&lt;/em&gt;&amp;nbsp;statement and execution of the sketch will continue below the closing brace of the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;switch&lt;/em&gt;&amp;nbsp;statement.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
If no matching case is found, then the code under the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;default&lt;/em&gt;&amp;nbsp;keyword will be run until its&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;break&lt;/em&gt;&amp;nbsp;statement is found.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
How the Example Sketch Works&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In the example sketch, the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;switch&lt;/em&gt;&amp;nbsp;statement is placed inside an&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement in the main loop. The&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;switch&lt;/em&gt;&amp;nbsp;statement will then only run if a new character is received from the Serial Monitor window.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
When a character is received from the Serial Monitor window, the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;switch&lt;/em&gt;&amp;nbsp;statement will check for a matching case value. If the character &#39;1&#39; is received, then the LED is switched on and a message displayed in the Serial Monitor window.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
If &#39;2&#39; is received, the LED is switched off. &#39;3&#39; displays a menu of the options available in the sketch.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
If any character is sent that does not match the characters in any of the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;case&lt;/em&gt;&amp;nbsp;statements, then the code in the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;default&lt;/em&gt;&amp;nbsp;part of the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;switch&lt;/em&gt;&amp;nbsp;body is run which displays a default message.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
The&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;break&lt;/em&gt;&amp;nbsp;Statement&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;break&lt;/em&gt;&amp;nbsp;statement is used in the example sketch to break out of the body of the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;switch&lt;/em&gt;&amp;nbsp;statement.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;break&lt;/em&gt;&amp;nbsp;can also be used to break out of any loop such as a&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;while&lt;/em&gt;&amp;nbsp;or&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/em&gt;&amp;nbsp;loop. As an example, a certain condition can be tested for in a loop using an&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement and if the statement evaluates to true, the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;break&lt;/em&gt;&amp;nbsp;statement can be run to break out of the loop.&lt;/div&gt;
&lt;div class=&quot;article_pg_nav&quot; style=&quot;background: rgb(255, 255, 255); border: 0px; font-family: arial, helvetica, verdana, sans-serif; font-size: 16px; margin: 20px 0px; min-height: 70px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;background: transparent; border: 0px; color: #444444; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://moroccoele.blogspot.com/feeds/5829810626366032544/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2535795214191795882/5829810626366032544' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/5829810626366032544'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/5829810626366032544'/><link rel='alternate' type='text/html' href='http://moroccoele.blogspot.com/2017/02/arduino-switch-and-break-statements.html' title='Arduino switch and break Statements'/><author><name>zouhair</name><uri>http://www.blogger.com/profile/03215618839043737171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/sqtFs_14Rqw/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2535795214191795882.post-4998348721878733097</id><published>2017-02-13T03:06:00.006-08:00</published><updated>2017-02-13T03:06:49.683-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Arduino"/><title type='text'>Logical Operators</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Logical operators can be used with&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;and&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if-else&lt;/em&gt;&amp;nbsp;to simplify and extend decision making.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The three logical operators are OR (||), AND (&amp;amp;&amp;amp;) and NOT (!) which are explained and demonstrated in this part of the course.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
The OR Logical Operator (||)&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The OR logical operator is written in sketches as two vertical pipe symbols (||) found on the same key as the backslash (\) on USA and other keyboards. Pressing&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Shift&lt;/strong&gt;&amp;nbsp;+&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;\&lt;/strong&gt;&amp;nbsp;(Shift and back slash keys) will type the vertical pipe character.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The following sketch demonstrates the use of the OR logical operator to check for the upper and lower-case versions of an alphabet character.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;pinMode&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;OUTPUT&lt;/span&gt;);  &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// LED on pin 13 of UNO&lt;/span&gt;
}

&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;char&lt;/span&gt; rx_byte;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;available&lt;/span&gt;() &amp;gt; 0) {    &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// is a character available?&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rx_byte&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;read&lt;/span&gt;();       &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;//&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (rx_byte == &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;a&#39;&lt;/span&gt; || rx_byte == &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;A&#39;&lt;/span&gt;) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;HIGH&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/span&gt; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;LOW&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;}
}&lt;/pre&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The sketch will switch the LED on the Arduino Uno board on if the lower-case character &#39;a&#39; or the upper-case character &#39;A&#39; is sent from the serial monitor window. If any other character is sent, the LED is switched off.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
How the Logical OR Operator Works&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The code below is taken from the above sketch and shows the logical OR operator.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (rx_byte == &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;a&#39;&lt;/span&gt; || rx_byte == &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;A&#39;&lt;/span&gt;) {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;HIGH&lt;/span&gt;);
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The code in the body of the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement will run if the variable&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;rx_byte&lt;/strong&gt;&amp;nbsp;contains &#39;a&#39; OR (||) if it contains &#39;A&#39;. The OR operator has been used to test for one&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;or&lt;/strong&gt;&amp;nbsp;the other character (A OR a).&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The code can be modified to switch the LED on if the character &#39;a&#39; or the character &#39;b&#39; or the character &#39;c&#39; is received, as this next code demonstrates.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; ((rx_byte == &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;a&#39;&lt;/span&gt;) || (rx_byte == &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;b&#39;&lt;/span&gt;) || (rx_byte == &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;c&#39;&lt;/span&gt;)) {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;HIGH&lt;/span&gt;);
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
In the above code, each equal to relational operator comparison has been put in parentheses () to make the code easier to read. This also avoids any misunderstanding about which operator is evaluated first (does the == or the || get evaluated first?).&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The == has a higher precedence than the || which means that == is evaluated first. Parentheses have the highest precedence, so anything placed in parentheses will be evaluated first. In this case it is not necessary to place the parentheses, but makes it easier to read.&lt;/div&gt;
&lt;div class=&quot;clr_flt&quot; style=&quot;background: rgb(255, 255, 255); border: 0px; clear: both; font-family: arial, helvetica, verdana, sans-serif; font-size: 16px; font-weight: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The AND Logical Operator (&amp;amp;&amp;amp;)&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The next sketch demonstrates the use of the logical AND operator. The sketch tests to see that a sequence of two characters has been received before turning the LED on.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 653.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;pinMode&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;OUTPUT&lt;/span&gt;);  &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// LED on pin 13 of UNO&lt;/span&gt;
}

&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;char&lt;/span&gt; first_char = 0;

&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;char&lt;/span&gt; rx_byte;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;available&lt;/span&gt;() &amp;gt; 0) {    &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// is a character available?&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rx_byte&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;read&lt;/span&gt;();       &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// read the character&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; ((first_char == &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;c&#39;&lt;/span&gt;) &amp;amp;&amp;amp; (rx_byte == &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;d&#39;&lt;/span&gt;)) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;HIGH&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/span&gt; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;first_char&amp;nbsp;=&amp;nbsp;rx_byte;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// save the character for next comparison&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;LOW&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;}
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
In this sketch, two characters must be sent in the right order to switch the LED on. First &#39;c&#39; must be sent, followed by &#39;d&#39;.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
This video shows the above sketch operating:&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe width=&quot;320&quot; height=&quot;266&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/jotKsBNZY34/0.jpg&quot; src=&quot;https://www.youtube.com/embed/jotKsBNZY34?feature=player_embedded&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
How the Logical AND Operator Works&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The AND operator from the above sketch is shown below.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; ((first_char == &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;c&#39;&lt;/span&gt;) &amp;amp;&amp;amp; (rx_byte == &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;d&#39;&lt;/span&gt;)) {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;HIGH&lt;/span&gt;);
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The LED will only switch on when the variable&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;first_char&lt;/strong&gt;&amp;nbsp;contains &#39;c&#39; AND the variable&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;rx_byte&lt;/strong&gt;&amp;nbsp;contains &#39;d&#39;.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The variable&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;first_char&lt;/strong&gt;&amp;nbsp;is used to store the current character received so that the next time the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement is evaluated, we can see if it was followed by &#39;d&#39; and if it contains &#39;c&#39;.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The Logical NOT Operator (!)&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The NOT operator can be used to check if a variable contains the value 0 – in other words it can be used to check if a variable evaluates to false.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;int x = 0;
if(!x) {
 // if not x - if x evaluates to false, code here will run
}

// this code is another way of writing the above code
if (x == 0) {
}&lt;/pre&gt;
&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://moroccoele.blogspot.com/feeds/4998348721878733097/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2535795214191795882/4998348721878733097' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/4998348721878733097'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/4998348721878733097'/><link rel='alternate' type='text/html' href='http://moroccoele.blogspot.com/2017/02/logical-operators.html' title='Logical Operators'/><author><name>zouhair</name><uri>http://www.blogger.com/profile/03215618839043737171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/jotKsBNZY34/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2535795214191795882.post-9037887293872798347</id><published>2017-02-13T03:05:00.002-08:00</published><updated>2017-02-13T03:05:18.729-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Arduino"/><title type='text'>Decisions with if-else-if</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if-else-if&lt;/em&gt;&amp;nbsp;construct allows further conditional expressions to be evaluated than the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if-else&lt;/em&gt;&amp;nbsp;construct covered previously.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
What this means is that we can add even more decision making capability to our Arduino sketches. A single variable can be checked to see if it contains any one of a number of different values and a decision can be made depending on which value the variable contains.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Using the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if-else-if&lt;/em&gt;&amp;nbsp;Construct&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if-else-if&lt;/em&gt;&amp;nbsp;construct is shown below.&lt;/div&gt;
&lt;br style=&quot;background-color: white; font-family: arial, helvetica, verdana, sans-serif; font-size: 16px;&quot; /&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (conditional expression 1) {
}
&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (conditional expression 2) {
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
As can be seen, the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if-else-if&lt;/em&gt;&amp;nbsp;construct allows a second conditional expression to be evaluated after the first&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
If the first conditional expression evaluates to true, then the code in the body of the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement will be run and the code in the body of the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else-if&lt;/em&gt;&amp;nbsp;statement will not be run.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Only if the first conditional expression evaluates to false, will the second conditional expression be evaluated. If the second conditional expression evaluates to true, the the code in the block below the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else-if&lt;/em&gt;&amp;nbsp;statement will run. If the second conditional expression evaluates to false, program execution will continue below the closing brace of the body of the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else-if&lt;/em&gt;&amp;nbsp;statement.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;em style=&quot;background: transparent; border: 0px; font-size: 18.4px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if-else-if Example Sketch&lt;/em&gt;&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The sketch below demonstrates the use of the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if-else-if&lt;/em&gt;&amp;nbsp;construct. If the character &#39;a&#39; is sent from the serial monitor window, then the LED will blink at a certain rate. If the character &#39;b&#39; is sent, the LED will blink at a faster rate.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 653.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;pinMode&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;OUTPUT&lt;/span&gt;);  &lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// LED on pin 13 of UNO&lt;/span&gt;
}

&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;char&lt;/span&gt; rx_byte = 0;

&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;available&lt;/span&gt;() &amp;gt; 0) {    &lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// is a character available?&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rx_byte&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;read&lt;/span&gt;();
&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (rx_byte == &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;a&#39;&lt;/span&gt;) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;HIGH&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay&lt;/span&gt;(500);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;LOW&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay&lt;/span&gt;(500);
&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (rx_byte == &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;b&#39;&lt;/span&gt;) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;HIGH&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay&lt;/span&gt;(200);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;LOW&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay&lt;/span&gt;(200);
&amp;nbsp;&amp;nbsp;}
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The video below shows the sketch running.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe width=&quot;320&quot; height=&quot;266&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/EqDSe6iX0oc/0.jpg&quot; src=&quot;https://www.youtube.com/embed/EqDSe6iX0oc?feature=player_embedded&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The first&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement gets a character from the serial port if one is available. The&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if-else-if&lt;/em&gt;&amp;nbsp;construct follows this (shown below).&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (rx_byte == &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;a&#39;&lt;/span&gt;) {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;HIGH&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay&lt;/span&gt;(500);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;LOW&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay&lt;/span&gt;(500);
}
&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (rx_byte == &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;b&#39;&lt;/span&gt;) {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;HIGH&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay&lt;/span&gt;(200);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;LOW&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay&lt;/span&gt;(200);
}
&lt;/pre&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Deciding the Rate at which to Blink the LED&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
This code simply checks which character the&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;rx_byte&lt;/strong&gt;&amp;nbsp;variable holds. If this variable contains &#39;a&#39;, then the code in the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;block will run which will blink the LED with a 500ms delay. This switches the LED on for 500ms using the&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay()&lt;/strong&gt;&amp;nbsp;function and then off for 500ms.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
If the variable holds the value &#39;b&#39;, then the LED will be blinked at a faster rate by changing the on and off times of the LED to 200ms.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Stopping the LED from Blinking&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
If any character besides &#39;a&#39; or &#39;b&#39; is sent, then the LED will stop flashing because neither of the conditional expressions will evaluate to true.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
When the Expression is Evaluated&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Note that this code is in the main Arduino loop, so the conditional expression(s) will be evaluated each time through the loop. If a character is received that causes a conditional expression to be true, then this condition will be true each time through the loop until a new character is received. This is because the character is stored in the variable and does not change until it is overwritten by a new character.&lt;/div&gt;
&lt;div class=&quot;clr_flt&quot; style=&quot;background: rgb(255, 255, 255); border: 0px; clear: both; font-family: arial, helvetica, verdana, sans-serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
The&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if-else-if-else&lt;/em&gt;&amp;nbsp;Construct&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In the same way that we could add an&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/em&gt;&amp;nbsp;statement below an&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement, we can add an&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/em&gt;&amp;nbsp;statement below the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if-else-if&lt;/em&gt;&amp;nbsp;construct as the sketch below shows.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
This sketch works in the same way as the previous sketch, except that when any character except &#39;a&#39; or &#39;b&#39; is sent, the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/em&gt;&amp;nbsp;block is run which flashes the LED even faster than the previous two blink rates&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 653.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;pinMode&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;OUTPUT&lt;/span&gt;);  &lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// LED on pin 13 of UNO&lt;/span&gt;
}

&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;char&lt;/span&gt; rx_byte = 0;

&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;available&lt;/span&gt;() &amp;gt; 0) {    &lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// is a character available?&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rx_byte&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;read&lt;/span&gt;();
&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (rx_byte == &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;a&#39;&lt;/span&gt;) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// the character &#39;a&#39; was received, blink the LED once per second&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;HIGH&lt;/span&gt;);  &lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// switch the LED on&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay&lt;/span&gt;(500);              &lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// leave the LED on for 500ms&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;LOW&lt;/span&gt;);   &lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// switch the LED off&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay&lt;/span&gt;(500);              &lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// leave the LED off for 500ms&lt;/span&gt;
&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (rx_byte == &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;b&#39;&lt;/span&gt;) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// the character &#39;b&#39; was received, blink the LED every 400ms&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;HIGH&lt;/span&gt;);  &lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// switch the LED on&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay&lt;/span&gt;(200);              &lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// leave the LED on for 200ms&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;LOW&lt;/span&gt;);   &lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// switch the LED off&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay&lt;/span&gt;(200);              &lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// leave the LED off for 200ms&lt;/span&gt;
&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/span&gt; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// any character except &#39;a&#39; or &#39;b&#39; was received&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;HIGH&lt;/span&gt;);  &lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// switch the LED on&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay&lt;/span&gt;(100);              &lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// leave the LED on for 100ms&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;LOW&lt;/span&gt;);   &lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// switch the LED off&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay&lt;/span&gt;(100);              &lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// leave the LED off for 100ms&lt;/span&gt;
&amp;nbsp;&amp;nbsp;}
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
When the sketch starts running, the LED immediately blinks at the fastest rate by running the code in the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/em&gt;&amp;nbsp;block. This is because the variable&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;rx_byte&lt;/strong&gt;&amp;nbsp;is initialized to 0 which of course is not &#39;a&#39; or &#39;b&#39;.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
If you want the sketch to blink the LED at the slowest rate when the sketch starts running, then initialize the variable to &#39;a&#39; as shown here.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;char&lt;/span&gt; rx_byte = &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;a&#39;&lt;/span&gt;;
&lt;/pre&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Evaluating More Conditional Expressions&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Even more conditional expressions can be evaluated by adding more&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else if&lt;/em&gt;&amp;nbsp;statements after the first&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement as shown here.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (conditional expression 1) {
}
&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (conditional expression 2) {
}
&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (conditional expression 3) {
}
&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (conditional expression 4) {
}
etc.&amp;nbsp;...
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
To perform a task only if none of the the conditional expressions evaluate to true, an&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/em&gt;&amp;nbsp;condition can be added at the end as shown below.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (conditional expression 1) {
}
&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (conditional expression 2) {
}
&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (conditional expression 3) {
}
&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (conditional expression 4) {
}
&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/span&gt; {
}&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://moroccoele.blogspot.com/feeds/9037887293872798347/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2535795214191795882/9037887293872798347' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/9037887293872798347'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/9037887293872798347'/><link rel='alternate' type='text/html' href='http://moroccoele.blogspot.com/2017/02/decisions-with-if-else-if.html' title='Decisions with if-else-if'/><author><name>zouhair</name><uri>http://www.blogger.com/profile/03215618839043737171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/EqDSe6iX0oc/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2535795214191795882.post-3249006342017299306</id><published>2017-02-13T03:02:00.001-08:00</published><updated>2017-02-13T03:02:07.303-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Arduino"/><title type='text'>Making Decisions with if-else</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Following on from&amp;nbsp;&lt;a href=&quot;https://startingelectronics.org/software/arduino/learn-to-program-course/09-if-statement&quot; style=&quot;background: transparent; border-bottom-color: rgb(19, 78, 139); border-bottom-style: dotted; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #134e8b; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;&quot;&gt;part 9 of the Arduino programming course&lt;/a&gt;&amp;nbsp;which covered the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement, we now look at the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if-else&lt;/em&gt;&amp;nbsp;construct.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
This construct adds more decision making capability to the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Using&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if-else&lt;/em&gt;&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
When using an&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement, the code in the body of the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement is run only when the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement evaluates to true. When it evaluates to false, program execution skips the code in the body of the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement and continues below the body of the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
By adding an&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/em&gt;&amp;nbsp;statement, code in the body of the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/em&gt;&amp;nbsp;statement will run only when its corresponding&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement evaluates to false.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The following code shows the syntax of the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if-else&lt;/em&gt;&amp;nbsp;construct.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (conditional expression) {
}
&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/span&gt; {
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The code below shows how the functioning of the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement compares to the functioning of the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if-else&lt;/em&gt;&amp;nbsp;construct.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;//&amp;nbsp;&quot;if&quot;&amp;nbsp;statement&lt;/span&gt;
&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (conditional expression) {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// Code placed here only runs if conditional expression is true&lt;/span&gt;
}
&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;//&amp;nbsp;Whether&amp;nbsp;the&amp;nbsp;conditional&amp;nbsp;expression&amp;nbsp;evaluates&amp;nbsp;to&amp;nbsp;true&amp;nbsp;or&amp;nbsp;false,&lt;/span&gt;
&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;//&amp;nbsp;code&amp;nbsp;placed&amp;nbsp;here&amp;nbsp;will&amp;nbsp;run&lt;/span&gt;

&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;//&amp;nbsp;&quot;if-else&quot;&amp;nbsp;construct&lt;/span&gt;
&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (conditional expression) {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// Body of the &quot;if&quot; statement between { and }&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// Works as a normal &quot;if&quot; statement, code placed here will only&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// run if the conditional expression evaluates to true&lt;/span&gt;
}
&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/span&gt; {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// Body of the &quot;else&quot; statement between { and }&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// Code placed here will always run if the conditional expression&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// from the &quot;if&quot; statement evaluates to false&lt;/span&gt;
}
&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;//&amp;nbsp;Code&amp;nbsp;placed&amp;nbsp;below&amp;nbsp;the&amp;nbsp;if-else&amp;nbsp;construct&amp;nbsp;will&amp;nbsp;always&amp;nbsp;run&amp;nbsp;whether&lt;/span&gt;
&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;//&amp;nbsp;the&amp;nbsp;conditional&amp;nbsp;expression&amp;nbsp;evaluated&amp;nbsp;to&amp;nbsp;true&amp;nbsp;or&amp;nbsp;false&lt;/span&gt;
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
When the conditional expression evaluates to&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;true&lt;/strong&gt;:&lt;/div&gt;
&lt;ol style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin: 0px 0px 7px; outline: 0px; overflow: hidden; padding: 0px 0px 0px 1.8em; vertical-align: baseline;&quot;&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Code in the body of the&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/strong&gt;&amp;nbsp;statement is run.&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Code in the body of the&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/strong&gt;&amp;nbsp;statement is not run.&lt;/li&gt;
&lt;/ol&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
When the conditional expression evaluates to&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;false&lt;/strong&gt;:&lt;/div&gt;
&lt;ol style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin: 0px 0px 7px; outline: 0px; overflow: hidden; padding: 0px 0px 0px 1.8em; vertical-align: baseline;&quot;&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Code in the body of the&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/strong&gt;&amp;nbsp;statement is not run.&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Code in the body of the&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/strong&gt;&amp;nbsp;statement is run.&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&quot;clr_flt&quot; style=&quot;background: rgb(255, 255, 255); border: 0px; clear: both; font-family: arial, helvetica, verdana, sans-serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;em style=&quot;background: transparent; border: 0px; font-size: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if-else&lt;/em&gt;&amp;nbsp;Example Sketch&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The sketch below shows an example of using the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if-else&lt;/em&gt;&amp;nbsp;construct. The LED will switch on if the character &#39;a&#39; is sent to the Arduino using the serial monitor window. If any other character except &#39;a&#39; is sent, then the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement evaluates to false and the code in the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/em&gt;&amp;nbsp;block is run which switches the LED off.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;pinMode&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;OUTPUT&lt;/span&gt;);  &lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// LED on pin 13 of UNO&lt;/span&gt;
}

&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;char&lt;/span&gt; rx_byte;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;available&lt;/span&gt;() &amp;gt; 0) {    &lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// is a character available?&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rx_byte&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;read&lt;/span&gt;();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (rx_byte == &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;a&#39;&lt;/span&gt;) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// switch the LED on if the character &#39;a&#39; is received&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;HIGH&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/span&gt; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// switch the LED off if any character except &#39;a&#39; is received&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;LOW&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;}
}
&lt;/pre&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Notes on the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 18.4px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if-else&lt;/em&gt;&amp;nbsp;Sketch Example&lt;/h3&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Nested&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if-else&lt;/em&gt;&amp;nbsp;Construct&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if-else&lt;/em&gt;&amp;nbsp;construct in the above example is actually placed inside the body of another&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement. This is called &quot;nesting&quot; and we say that the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if-else&lt;/em&gt;&amp;nbsp;is nested inside the first&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
To make this clearer, this is the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if-else&lt;/em&gt;&amp;nbsp;construct that is nested:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (rx_byte == &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;a&#39;&lt;/span&gt;) {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// switch the LED on if the character &#39;a&#39; is received&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;HIGH&lt;/span&gt;);
}
&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/span&gt; {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// switch the LED off if any character except &#39;a&#39; is received&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;LOW&lt;/span&gt;);
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The above code is nested inside this&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statements body:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;available&lt;/span&gt;() &amp;gt; 0) {    &lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// is a character available?&lt;/span&gt;
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
This video shows the sketch operating.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe width=&quot;320&quot; height=&quot;266&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/cAcd5sJjyCA/0.jpg&quot; src=&quot;https://www.youtube.com/embed/cAcd5sJjyCA?feature=player_embedded&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
How the Sketch Works&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The example sketch is based on the sketch from the previous part of this course. Instead of switching the LED off when only &#39;b&#39; is sent, the LED will switch off when any character except &#39;a&#39; is sent.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The character &#39;a&#39; will switch the LED on as in the previous sketch because the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;conditional expression evaluates to true when &#39;a&#39; is received. Any other character received will cause the conditional expression to evaluate to false. When the expression evaluates to false, the body of the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement is not run, but the body of the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/em&gt;&amp;nbsp;statement is run instead which turns the LED off.&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://moroccoele.blogspot.com/feeds/3249006342017299306/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2535795214191795882/3249006342017299306' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/3249006342017299306'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/3249006342017299306'/><link rel='alternate' type='text/html' href='http://moroccoele.blogspot.com/2017/02/making-decisions-with-if-else.html' title='Making Decisions with if-else'/><author><name>zouhair</name><uri>http://www.blogger.com/profile/03215618839043737171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/cAcd5sJjyCA/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2535795214191795882.post-8282566793358534032</id><published>2017-02-13T03:00:00.001-08:00</published><updated>2017-02-13T03:00:10.135-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Arduino"/><title type='text'>The Arduino if Statement</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In this part of the Arduino programming course, the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement is used to show how decisions can be made in a sketch.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
An&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement is used to check for keyboard input to the Arduino that a user types into the Serial Monitor Window of the Arduino IDE.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Further decisions can be made, depending on which key the user presses, for example, if the &#39;1&#39; key is pressed, the on-board LED of the Arduino can be switched on and if the &#39;0&#39; key is pressed, the LED can be switched off while all other key presses are ignored.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Using the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;Statement&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The sketch below shows the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement being used in a sketch to check if a character has been sent from the Arduino IDE serial monitor window.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
}

&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;char&lt;/span&gt; rx_byte;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;available&lt;/span&gt;() &amp;gt; 0) {    &lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// is a character available?&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rx_byte&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;read&lt;/span&gt;();       &lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// get the character&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;You typed: &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(rx_byte);
&amp;nbsp;&amp;nbsp;}
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
If the user sends a character from the serial monitor window, the Arduino sends back the text &quot;You typed: X&quot;, where X is the character that the user typed.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The video below shows the sketch running.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe width=&quot;320&quot; height=&quot;266&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/vaZ3fjnYepM/0.jpg&quot; src=&quot;https://www.youtube.com/embed/vaZ3fjnYepM?feature=player_embedded&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
How the Sketch Works&lt;/h3&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Arduino&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;Statement Structure&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The structure of an&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement is shown here:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (conditional expression) {
&amp;nbsp;&amp;nbsp;Body of if statement
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
If the conditional expression evaluates to true, the code in the body of the statement is run. If the conditional statement evaluates to false, none of the code in the body of the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement will be run.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Checking for a Character from the Serial Monitor Window&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In the example sketch, the value that&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial.available()&lt;/strong&gt;&amp;nbsp;returns will only be greater than 0 if one or more characters has been received by the Arduino from the serial monitor window.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement will only evaluate to true if one or more characters has been received.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
When no characters have been sent to the Arduino, the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement will be evaluated each time through the main loop and evaluate to false each time. The code in the body of the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement will therefore not be run.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
As soon as a character is sent from the serial monitor window,&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial.available()&lt;/strong&gt;&amp;nbsp;returns 1. When the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement is evaluated again, it evaluates to true (because 1 &amp;gt; 0) and the code in the body of the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement is run.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The character that was sent from the serial monitor window is the stored in the&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;rx_byte&lt;/strong&gt;&amp;nbsp;variable using the following line of code.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;rx_byte&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;read&lt;/span&gt;();       &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// get the character&lt;/span&gt;
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Because the character has been stored, it can now be sent back to the serial monitor window with some preceding text.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Using the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;Statement to Switch On an LED&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement can be used to make a decision to switch on an LED if a certain character is received as this next example shows.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;pinMode&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;OUTPUT&lt;/span&gt;);  &lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// LED on pin 13 of UNO&lt;/span&gt;
}

&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;char&lt;/span&gt; rx_byte;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;available&lt;/span&gt;() &amp;gt; 0) {    &lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// is a character available?&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rx_byte&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;read&lt;/span&gt;();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (rx_byte == &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;a&#39;&lt;/span&gt;) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;HIGH&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;}
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In this sketch, if the character sent from the serial monitor window is &#39;a&#39;, then the LED on pin 13 of the Arduino will be switched on. If any other character is sent, nothing will happen.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The if statement:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (rx_byte == &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;a&#39;&lt;/span&gt;)
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
will only evaluate to true if the character received from the serial monitor window and stored in the variable&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;rx_byte&lt;/strong&gt;&amp;nbsp;is equal to &#39;a&#39;.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Switching the LED Off Again&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The above sketch can be modified to add another&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement that can be used to switch the LED off again.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The sketch below will switch the LED on if &#39;a&#39; is sent to the Arduino and switch the LED off if &#39;b&#39; is sent to the Arduino (note that these are case sensitive, so &#39;A&#39; and &#39;B&#39; won&#39;t work).&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;pinMode&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;OUTPUT&lt;/span&gt;);  &lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// LED on pin 13 of UNO&lt;/span&gt;
}

&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;char&lt;/span&gt; rx_byte;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;available&lt;/span&gt;() &amp;gt; 0) {    &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// is a character available?&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rx_byte&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;read&lt;/span&gt;();       &lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;//&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (rx_byte == &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;a&#39;&lt;/span&gt;) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;HIGH&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (rx_byte == &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&#39;b&#39;&lt;/span&gt;) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(13, &lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;LOW&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;}
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Now it the character &#39;b&#39; is sent, the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement testing for &#39;a&#39; evaluates to false, but the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/em&gt;&amp;nbsp;statement testing for the character &#39;b&#39; evaluates to true and the LED is switched off.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
A more efficient way of dealing with switching the LED on and off is dealt with in the next part of the course which covers the&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/strong&gt;&amp;nbsp;and&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else if&lt;/strong&gt;&amp;nbsp;statements that are used with the&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/strong&gt;&amp;nbsp;statement.&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://moroccoele.blogspot.com/feeds/8282566793358534032/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2535795214191795882/8282566793358534032' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/8282566793358534032'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/8282566793358534032'/><link rel='alternate' type='text/html' href='http://moroccoele.blogspot.com/2017/02/the-arduino-if-statement.html' title='The Arduino if Statement'/><author><name>zouhair</name><uri>http://www.blogger.com/profile/03215618839043737171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/vaZ3fjnYepM/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2535795214191795882.post-3476736612479476502</id><published>2017-02-13T02:58:00.002-08:00</published><updated>2017-02-13T02:58:52.094-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Arduino"/><title type='text'>The Arduino while and do while Loops</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;while&lt;/em&gt;&amp;nbsp;loop is similar to the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/em&gt;&amp;nbsp;loop that was explained in the&amp;nbsp;&lt;a href=&quot;https://startingelectronics.org/software/arduino/learn-to-program-course/07-for-loop&quot; style=&quot;background: transparent; border-bottom-color: rgb(19, 78, 139); border-bottom-style: dotted; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #134e8b; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;&quot;&gt;previous part of this Arduino programming course&lt;/a&gt;. The main difference is that the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;while&lt;/em&gt;&amp;nbsp;loop separates the elements of the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/em&gt;&amp;nbsp;loop as will be shown.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Another loop called the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;do while&lt;/em&gt;&amp;nbsp;loop is also covered. The&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;do while&lt;/em&gt;&amp;nbsp;loop is always run at least once before any tests are done that could break program execution out of the loop.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
The&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;while&lt;/em&gt;&amp;nbsp;Loop&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The sketch that follows does exactly the same as the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/em&gt;&amp;nbsp;loop sketch from part 7 of this course, except that it uses the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;while&lt;/em&gt;&amp;nbsp;loop so that we can see the similarities between the two loops.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; i = 0;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;while&lt;/span&gt; (i &amp;lt; 10) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;i = &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(i);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;i++;
&amp;nbsp;&amp;nbsp;}
}

&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
}
&lt;/pre&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;em style=&quot;background: transparent; border: 0px; font-size: 18.4px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;while&lt;/em&gt;&amp;nbsp;Loop Structure&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;while&lt;/em&gt;&amp;nbsp;loop has a structure as follows:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;while&lt;/span&gt; (loop test expression goes here) {
&amp;nbsp;&amp;nbsp;Statements that run in the loop go here
&amp;nbsp;&amp;nbsp;Statement 1
&amp;nbsp;&amp;nbsp;Statement 2
&amp;nbsp;&amp;nbsp;...
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;while&lt;/em&gt;&amp;nbsp;loop starts with the&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;while&lt;/strong&gt;&amp;nbsp;keyword followed by a test expression between opening and closing parentheses. Opening and closing braces denote the body of the loop.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Test Expression&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
As with the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/em&gt;&amp;nbsp;loop, the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;while&lt;/em&gt;&amp;nbsp;loop has a test expression that will determine whether the statements in the loop will run or not. If the test expression evaluates to&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;true&lt;/strong&gt;, the loop statements are run. If the test expression evaluates to&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;false&lt;/strong&gt;, the loop statements will not be run, but the statements that follow the closing brace of the loop will be run – i.e. execution continues outside and below the loop.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Initialize Expression&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/em&gt;&amp;nbsp;loop had an initialize expression as part of the loop. The&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;while&lt;/em&gt;&amp;nbsp;loop can use any variable from the sketch that contains a valid value. In the example sketch, the variable used in the loop (&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i&lt;/strong&gt;) must be initialized when it is defined, otherwise it will contain any random value.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Increment Expression&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
An increment expression was used in the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/em&gt;&amp;nbsp;loop examples in the previous part of this course. In the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;while&lt;/em&gt;&amp;nbsp;loop example, the increment expression is placed inside the loop body.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
How the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 18.4px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;while&lt;/em&gt;&amp;nbsp;Loop Example Works&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In the example sketch, the following happens:&lt;/div&gt;
&lt;ol style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin: 0px 0px 7px; outline: 0px; overflow: hidden; padding: 0px 0px 0px 1.8em; vertical-align: baseline;&quot;&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;The variable&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i&lt;/strong&gt;&amp;nbsp;is initialized to 0 when the sketch starts running.&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;The&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;while&lt;/em&gt;&amp;nbsp;loop evaluates the test expression&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(i &amp;lt; 10)&lt;/strong&gt;.&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;The test expression evaluates to&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;true&lt;/strong&gt;&amp;nbsp;because&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i&lt;/strong&gt;&amp;nbsp;is less than 10.&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Because the test expression is true, the statements in the loop run.&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;The current value of&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i&lt;/strong&gt;&amp;nbsp;is printed and then incremented.&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;When the bottom of the loop is reached, execution is started at the top of the loop again.&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;The test expression is evaluated again, it is true again, so the loop runs again.&lt;/li&gt;
&lt;/ol&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Only when the variable&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i&lt;/strong&gt;&amp;nbsp;has been incremented to 10, will the loop expression evaluate to&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;false&lt;/strong&gt;&amp;nbsp;and the loop will be exited.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;em style=&quot;background: transparent; border: 0px; font-size: 18.4px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;while&lt;/em&gt;&amp;nbsp;Loop Example 2&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In the example sketch below, the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;while&lt;/em&gt;&amp;nbsp;loop is used to count up to twenty-five in fives by adding five to a variable each time through the loop.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; sum = 0;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// count up to 25 in 5s&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;while&lt;/span&gt; (sum &amp;lt; 25) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sum&amp;nbsp;=&amp;nbsp;sum&amp;nbsp;+&amp;nbsp;5;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;sum = &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(sum);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay&lt;/span&gt;(500);                &lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// 500ms delay&lt;/span&gt;
&amp;nbsp;&amp;nbsp;}
}

&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The video below shows the sketch running.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe width=&quot;320&quot; height=&quot;266&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/rx8DRG24Nvs/0.jpg&quot; src=&quot;https://www.youtube.com/embed/rx8DRG24Nvs?feature=player_embedded&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In this sketch, a variable called&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;sum&lt;/strong&gt;&amp;nbsp;is defined and initialized to 0. The test expression in the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;while&lt;/em&gt;&amp;nbsp;loop tests if&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;sum&lt;/strong&gt;&amp;nbsp;contains a value less than 25.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Inside the loop, the&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;sum&lt;/strong&gt;&amp;nbsp;variable is incremented by 5 each time through the loop by the arithmetic expression:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&amp;nbsp;&amp;nbsp;sum&amp;nbsp;=&amp;nbsp;sum&amp;nbsp;+&amp;nbsp;5;
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
This expression means &quot;add 5 to the&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;sum&lt;/strong&gt;&amp;nbsp;variable&quot;.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The value that the&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;sum&lt;/strong&gt;&amp;nbsp;variable holds is then printed out, followed by a half-second delay.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Because the value of the variable is first incremented and then printed out, we see the value 5 printed first and not the value of 0 that it was initialized to.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Although the test expression will evaluate to false when&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;sum == 25&lt;/strong&gt;, 25 is still the last number that is printed. This is because the last time that the test expression evaluates to true is when&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;sum == 20&lt;/strong&gt;, but&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;sum&lt;/strong&gt;&amp;nbsp;is then incremented to 25 and printed before the test expression is evaluated again.&lt;/div&gt;
&lt;div class=&quot;clr_flt&quot; style=&quot;background: rgb(255, 255, 255); border: 0px; clear: both; font-family: arial, helvetica, verdana, sans-serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
The&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;do while&lt;/em&gt;&amp;nbsp;Loop&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;do while&lt;/em&gt;&amp;nbsp;loop works in the same way as the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;while&lt;/em&gt;&amp;nbsp;loop, except that it always runs once even if the test expression evaluates to false.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;em style=&quot;background: transparent; border: 0px; font-size: 18.4px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;do while&lt;/em&gt;&amp;nbsp;Loop Structure&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;do while&lt;/em&gt;&amp;nbsp;loop consists of two keywords&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;do&lt;/strong&gt;&amp;nbsp;and&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;while&lt;/strong&gt;, as shown below.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;do&lt;/span&gt; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Statements that run in the loop go here
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Statement 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Statement 2
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;...
}&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;while&lt;/span&gt; (test expression goes here);
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The body of the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;do while&lt;/em&gt;&amp;nbsp;loop falls between opening and closing braces and contains statements that are to be run in the loop.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;while&lt;/strong&gt;&amp;nbsp;keyword and test expression come after the body of the loop and are terminated by a semicolon (&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;;&lt;/strong&gt;).&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;em style=&quot;background: transparent; border: 0px; font-size: 18.4px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;do while&lt;/em&gt;&amp;nbsp;Loop Example&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
This example demonstrates the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;do while&lt;/em&gt;&amp;nbsp;loop.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; sum = 0;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// count up to 25 in 5s&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;do&lt;/span&gt; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sum&amp;nbsp;=&amp;nbsp;sum&amp;nbsp;+&amp;nbsp;5;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;sum = &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(sum);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay&lt;/span&gt;(500);                &lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// 500ms delay&lt;/span&gt;
&amp;nbsp;&amp;nbsp;}&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;while&lt;/span&gt; (sum &amp;lt; 25);
}

&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
All the statements are run in the loop body before the test expression is evaluated.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
If&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;sum&lt;/strong&gt;&amp;nbsp;is initialized to a value of 25 when it is defined, as shown in the sketch below, the loop will run once and 30 will be printed. The loop will then not run again because the test expression evaluates to false.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; sum = 25;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// count up to 25 in 5s&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;do&lt;/span&gt; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sum&amp;nbsp;=&amp;nbsp;sum&amp;nbsp;+&amp;nbsp;5;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;sum = &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(sum);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay&lt;/span&gt;(500);                &lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// 500ms delay&lt;/span&gt;
&amp;nbsp;&amp;nbsp;}&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;while&lt;/span&gt; (sum &amp;lt; 25);
}

&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Using the same sketch, but changing the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;do while&lt;/em&gt;&amp;nbsp;loop to a&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;while&lt;/em&gt;&amp;nbsp;loop, as shown below, the statements in the loop body will never run. This is because the test expression is evaluated before executing statements in the loop body. The test expression immediately evaluates to false, so the loop statements will never run.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; sum = 25;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// count up to 25 in 5s&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;while&lt;/span&gt; (sum &amp;lt; 25) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sum&amp;nbsp;=&amp;nbsp;sum&amp;nbsp;+&amp;nbsp;5;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;sum = &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(sum);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay&lt;/span&gt;(500);                &lt;span style=&quot;background: transparent; border: 0px; color: #434f54; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// 500ms delay&lt;/span&gt;
&amp;nbsp;&amp;nbsp;}
}

&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In the above example, no output will be seen in the serial monitor window when the sketch is run. The&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;while&lt;/em&gt;&amp;nbsp;loop evaluates to false and then execution drops straight into the empty main Arduino loop&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://moroccoele.blogspot.com/feeds/3476736612479476502/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2535795214191795882/3476736612479476502' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/3476736612479476502'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/3476736612479476502'/><link rel='alternate' type='text/html' href='http://moroccoele.blogspot.com/2017/02/the-arduino-while-and-do-while-loops.html' title='The Arduino while and do while Loops'/><author><name>zouhair</name><uri>http://www.blogger.com/profile/03215618839043737171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/rx8DRG24Nvs/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2535795214191795882.post-602993962372428726</id><published>2017-02-13T02:55:00.001-08:00</published><updated>2017-02-13T02:55:04.458-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Arduino"/><title type='text'>The Arduino for Loop</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
We have already looked at one type of loop on this course namely,&amp;nbsp;&lt;a href=&quot;https://startingelectronics.org/software/arduino/learn-to-program-course/02-main-loop-calling-functions/&quot; style=&quot;background: transparent; border-bottom-color: rgb(19, 78, 139); border-bottom-style: dotted; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #134e8b; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;&quot;&gt;the Arduino main loop in part 2&lt;/a&gt;.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In this part of the Arduino programming course, we look at another kind of loop called the &quot;for&quot; loop.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Whereas statements or code in the Arduino main loop will run continually and never exit the loop, the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/em&gt;&amp;nbsp;loop allows us to loop through code a certain number of times before exiting the loop.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
A common way to use the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/em&gt;&amp;nbsp;loop is with the increment operator that was covered in the&amp;nbsp;&lt;a href=&quot;https://startingelectronics.org/software/arduino/learn-to-program-course/06-increment-operator-commenting/&quot; style=&quot;background: transparent; border-bottom-color: rgb(19, 78, 139); border-bottom-style: dotted; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #134e8b; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;&quot;&gt;previous part of this course&lt;/a&gt;.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Using the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/em&gt;&amp;nbsp;Loop&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The following sketch demonstrates the use of the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/em&gt;&amp;nbsp;loop.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; i;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/span&gt; (i = 0; i &amp;lt; 10; i++) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;i = &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(i);
&amp;nbsp;&amp;nbsp;}
}

&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Load the sketch to your Arduino to see how it runs. This video shows the sketch running.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe width=&quot;320&quot; height=&quot;266&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/5a2im1PcVjc/0.jpg&quot; src=&quot;https://www.youtube.com/embed/5a2im1PcVjc?feature=player_embedded&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
How the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 18.4px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/em&gt;&amp;nbsp;Loop Works&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The image below shows the parts of the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/em&gt;&amp;nbsp;loop&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYmD67l9onYdBl3rzN8kwptWTw3hSmyAbbnVWkD3-Wi1ylQ1QbI4o9nLFgOIGH2YdEXFvcGScAsHKy4p43vcBmNd9KQupffzOp44jFIZapZOxokU2TZxud893wQx5viLjmQ_edkZJTR_cz/s1600/2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;168&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYmD67l9onYdBl3rzN8kwptWTw3hSmyAbbnVWkD3-Wi1ylQ1QbI4o9nLFgOIGH2YdEXFvcGScAsHKy4p43vcBmNd9KQupffzOp44jFIZapZOxokU2TZxud893wQx5viLjmQ_edkZJTR_cz/s320/2.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;em style=&quot;background: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/em&gt;&amp;nbsp;Loop Structure&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
A basic&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/em&gt;&amp;nbsp;loop is started as follows:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/span&gt; () {
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Three expressions are added between the opening and closing parentheses&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;()&lt;/strong&gt;&amp;nbsp;that determine how many times the statements in the loop are run before exiting the loop. When the loop is exited, program execution continues below the loop – i.e. statements outside and below the loop are executed from top to bottom.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The body of the loop between the opening and closing braces&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;{}&lt;/strong&gt;&amp;nbsp;contains statements that will run in the loop.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The expressions between the parentheses are called the initialize expression, test expression and increment expression.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
A variable must be defined to use in the three loop expressions. In the example sketch an integer variable called&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i&lt;/strong&gt;&amp;nbsp;is used.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The three loop expressions must appear in the order: initialize, test and increment. They are separated by semicolons (&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;;&lt;/strong&gt;). The increment expression does not end with a semicolon.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Initialize Expression&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The initialize expression is only run once at the time that the loop starts. It initializes our&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i&lt;/strong&gt;&amp;nbsp;variable to zero (0) in the example sketch.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Test Expression&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The test expression determines when we break out of the loop. It is used to set the number of times that the statements in the body of the loop are run.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
When the test expression evaluates to&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;true&lt;/strong&gt;, the statements in the loop body will be run. When the test expression evaluates to&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;false&lt;/strong&gt;&amp;nbsp;the loop will not be run again, but will be exited.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The test expression is evaluated every time that execution starts at the top of the loop.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Increment Expression&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The increment expression is used to change the value that the&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i&lt;/strong&gt;&amp;nbsp;variable holds. It is run every time that execution starts at the top of the loop.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Program Flow in the Loop&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The image below shows how program flow works in the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/em&gt;&amp;nbsp;loop.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigsVJb97dNFvBI-TFOuQj1VC02yuRKw7_KCqqWug9oNSBx_yv2T2vt8zFnzPb14cHU2IpEX3eWQYApjk5OA40XboHI_FAjKIRjup07o2Qy4m_zoWt5ombs3caF4o-ucpeYfUXid1vwCZWA/s1600/3.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;132&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigsVJb97dNFvBI-TFOuQj1VC02yuRKw7_KCqqWug9oNSBx_yv2T2vt8zFnzPb14cHU2IpEX3eWQYApjk5OA40XboHI_FAjKIRjup07o2Qy4m_zoWt5ombs3caF4o-ucpeYfUXid1vwCZWA/s320/3.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;pic_caption&quot; style=&quot;background: rgb(255, 255, 255); border: 0px; color: blue; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.8em; font-weight: bold; line-height: 16.64px; margin-bottom: 16px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;em style=&quot;background: transparent; border: 0px; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/em&gt;&amp;nbsp;Loop Program Flow&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
First Time Through the Loop&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The first time through the loop,&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i&lt;/strong&gt;&amp;nbsp;is initialized to 0, the test expression tests whether&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i &amp;lt; 10 (0 &amp;lt; 10)&lt;/strong&gt;&amp;nbsp;which is true, so the statements in the loop will run.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Because the post increment operator is used with the variable,&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i&lt;/strong&gt;&amp;nbsp;will only be incremented at the end of the loop. The statements in the loop run and print the value of&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i&lt;/strong&gt;&amp;nbsp;as 0 because it has not yet been incremented.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
We therefore have this:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;i is initialized to 0
i contains 0
i &amp;lt; 10 evaluates to true or 1 because i is less than 10
The two statements in the loop run, print i as 0
At the end of the loop i is incremented so i == 1
&lt;/pre&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Second Time Through the Loop&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The second time through the loop,&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i&lt;/strong&gt;&amp;nbsp;now contains 1 as it was incremented at the bottom of the loop. The test expression now tests whether&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i &amp;lt; 10 (1 &amp;lt; 10)&lt;/strong&gt;&amp;nbsp;which is true, so the statements in the loop will run again. The&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i&lt;/strong&gt;&amp;nbsp;variable will only be incremented to 2 at the bottom of the loop, so 1 is printed to the serial monitor window.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
We now have this:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;i is not initialized again
i contains 1
i &amp;lt; 10 evaluates to true or 1 because i is less than 10
The two statements in the loop run, print i as 1
At the end of the loop i is incremented so i == 2
&lt;/pre&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Last Time Through the Loop&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Execution of the loop will continue and&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i&lt;/strong&gt;&amp;nbsp;will be incremented every time.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The last time through the loop, we have this:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;i is not initialized again
i contains 9
i &amp;lt; 10 evaluates to true or 1 because i is less than 10
The two statements in the loop run, print i as 9
At the end of the loop i is incremented so i == 10
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Execution starts at the top of the loop again, the evaluation expression is tested.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
We now have this:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;i is not initialized again
i contains 10
i &amp;lt; 10 evaluates to false or 0 because i is not less than 10 (it is equal to 10)
The statements in the loop are not run again
The loop is exited
The statement below the closing bracket of the loop will be run
&lt;/pre&gt;
&lt;div class=&quot;clr_flt&quot; style=&quot;background: rgb(255, 255, 255); border: 0px; clear: both; font-family: arial, helvetica, verdana, sans-serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Alternative Way of Writing the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 18.4px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/em&gt;&amp;nbsp;Loop&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The sketch that follows shows that the variable used in the loop expressions can also be defined in the loop and does not have to be defined outside the loop as the previous sketch did.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; i = 0; i &amp;lt; 10; i++) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;i = &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(i);
&amp;nbsp;&amp;nbsp;}
}

&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
This sketch works exactly the same as the previous sketch and outputs the numbers 0 to 9.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
A Loop Within a Loop&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The next sketch uses a&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/strong&gt;&amp;nbsp;loop within the Arduino main loop.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
}

&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; i = 0; i &amp;lt; 10; i++) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;i = &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(i);
&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay&lt;/span&gt;(1000);
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/em&gt;&amp;nbsp;loop works exactly the same as it did before, but now after it has been exited, the delay() function is run to give a 1 second delay. The end of the Arduino main loop&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop()&lt;/strong&gt;&amp;nbsp;is reached, so the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/em&gt;&amp;nbsp;loop is run again.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
When the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/em&gt;&amp;nbsp;loop is run again,&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i&lt;/strong&gt;&amp;nbsp;is initialized to 0 because the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/em&gt;&amp;nbsp;loop is being started from the top again. It then runs again as previously described.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/em&gt;&amp;nbsp;loop and delay() function will be run continually because the main Arduino loop never exits.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;br style=&quot;color: black; font-size: 16px;&quot; /&gt;&lt;br style=&quot;color: black; font-size: 16px;&quot; /&gt;&lt;br style=&quot;color: black; font-size: 16px;&quot; /&gt;&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Notes on the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 20.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/em&gt;&amp;nbsp;Loop Sketch Examples&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Note the following about the sketch examples in this part of the course.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Initialize Expression&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The initialize expression in the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/em&gt;&amp;nbsp;loop does not have to be initialized to zero (0), but can be initialized to any integer value, even a negative value.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Increment Expression&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The increment expression is used to change the value of the variable that the test expression tests. This does not have to be an increment operator, but can be the decrement operator (subtracts 1 from the variable) or any other arithmetic expression.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The increment operator has been used in the example sketches to keep things simple at the beginning of the course, and because it is a common way of using the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/em&gt;&amp;nbsp;loop. We will look at other ways to use the&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/em&gt;&amp;nbsp;loop later in the course.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Counting from Zero (0)&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Note that in the example sketches, that the value that the&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i&lt;/strong&gt;&amp;nbsp;variable contains is initialized to 0 and not 1. We therefore print out a count value that starts at 0 and ends at 9.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The loop is actually run 10 times and not 9 times. This is because we are starting at 0 – 0 to 9 are 10 numbers, 1 to 9 are 9 numbers, 1 to 10 are 10 numbers.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
This list shows the number of times through the loop on the left and the value of&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i&lt;/strong&gt;&amp;nbsp;on the right.&lt;/div&gt;
&lt;ol style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin: 0px 0px 7px; outline: 0px; overflow: hidden; padding: 0px 0px 0px 1.8em; vertical-align: baseline;&quot;&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i = 0&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i = 1&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i = 2&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i = 3&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i = 4&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i = 5&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i = 6&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i = 7&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i = 8&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;i = 9&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://moroccoele.blogspot.com/feeds/602993962372428726/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2535795214191795882/602993962372428726' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/602993962372428726'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/602993962372428726'/><link rel='alternate' type='text/html' href='http://moroccoele.blogspot.com/2017/02/the-arduino-for-loop.html' title='The Arduino for Loop'/><author><name>zouhair</name><uri>http://www.blogger.com/profile/03215618839043737171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/5a2im1PcVjc/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2535795214191795882.post-8266011844303229331</id><published>2017-02-13T02:49:00.002-08:00</published><updated>2017-02-13T02:49:27.658-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Arduino"/><title type='text'>Increment Operator and Commenting</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The increment operator is an Arduino arithmetic operator that is used to increment an integer variable by a value of one. We look at how to use the increment operator in this part of the Arduino programming course.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Comments in programming are notes that are written in a program (or sketch) by the programmer. These notes are used to explain what the code is doing, or to add other useful human readable information to the code. How, when and why to use comments are explained at the end of this part of the course.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Arduino Increment Operator&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The Arduino increment operator is used to increase the value that a variable holds by one. This is useful in certain types of loops as will be shown later in this course.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Increment Operator Example 1&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The example below shows the increment operator being used to increment a value several times.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; count = 0;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(count++);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(count++);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(count++);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(count);
}

&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
}
&lt;/pre&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Sketch Output&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The output of the sketch in the Arduino serial monitor window is shown here.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoyENEDs4YQxUpPwcjdLZADQluvebauDGIrDFFyFI-7Bq7JeSbIZoQ_U1sy2nRUarE5n8gI1mKu6PnZR7G5IEyk68FUqlhW0GNSbrXGp-gJA9x7p3NP2eLpcT0lebOdjr4ok-w8bcG58td/s1600/1.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;176&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoyENEDs4YQxUpPwcjdLZADQluvebauDGIrDFFyFI-7Bq7JeSbIZoQ_U1sy2nRUarE5n8gI1mKu6PnZR7G5IEyk68FUqlhW0GNSbrXGp-gJA9x7p3NP2eLpcT0lebOdjr4ok-w8bcG58td/s320/1.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Initializing the Variable to Increment&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In the above example, the variable&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;count&lt;/strong&gt;&amp;nbsp;is defined and initialized to a value of 0 (zero).&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
It is important to initialize this variable before using the increment operator because if it is not initialized, it can contain any random value. Here we initialize it to 0, but could have used any other integer value.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Printing and Incrementing&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial.println()&lt;/strong&gt;&amp;nbsp;is used to print the value of&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;count&lt;/strong&gt;, but in the same statement, the increment operator (&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;++&lt;/strong&gt;) is used to increase the value that the&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;count&lt;/strong&gt;&amp;nbsp;variable holds.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The increment operation causes the value in&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;count&lt;/strong&gt;&amp;nbsp;to increase from 0 to 1.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Post Incrementing&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Placing the&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;++&lt;/strong&gt;&amp;nbsp;after the variable name (&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;count++&lt;/strong&gt;) is a post increment operation. This means that the variable is used in the statement and only incremented after this.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Because of the post increment operation, the initial value of&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;count&lt;/strong&gt;&amp;nbsp;(which is 0) is printed by the first println() function, and only incremented after this.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The next println() function prints the new incremented value (now 1) and then the increment operator in the statement increments the value of&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;count&lt;/strong&gt;&amp;nbsp;after it has been printed – it is now incremented to 2.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The third println() statement prints out 2 and increments the value in&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;count&lt;/strong&gt;&amp;nbsp;to 3.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The final println() statement prints out the value of&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;count&lt;/strong&gt;&amp;nbsp;but does not use the increment operator. It prints out the value of 3 which the variable was previously incremented to.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Increment Operator Example 2&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The following sketch does exactly the same as the previous sketch, but the increment operations and print operations have been separated into their own statements.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
This example may help to clarify what is happening in the previous example. We can see that the first println() statements prints the value of&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;count&lt;/strong&gt;&amp;nbsp;and only after this is the value in&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;count&lt;/strong&gt;&amp;nbsp;incremented.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; count = 0;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(count);
&amp;nbsp;&amp;nbsp;count++;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(count);
&amp;nbsp;&amp;nbsp;count++;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(count);
&amp;nbsp;&amp;nbsp;count++;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(count);
}

&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
From these two examples, we can see that this single line of code:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(count++);
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Is the same as these two lines of code:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(count);
count++;
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The important thing to note is that the incrementing of the variable takes place after printing it, so the value that the variable holds is printed before it is updated to the new incremented value.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
As always, load the code to your Arduino and experiment with it.&lt;/div&gt;
&lt;div class=&quot;clr_flt&quot; style=&quot;background: rgb(255, 255, 255); border: 0px; clear: both; font-family: arial, helvetica, verdana, sans-serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Commenting Sketches&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Commenting sketches allows you to write your own text notes along with the code of the sketch. The next sketch shows two ways of writing comments.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #95a5a6; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;/*&lt;/span&gt;
&lt;span style=&quot;background: transparent; border: 0px; color: #95a5a6; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Sketch&amp;nbsp;Name:&amp;nbsp;&amp;nbsp;comments&lt;/span&gt;
&lt;span style=&quot;background: transparent; border: 0px; color: #95a5a6; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;
&lt;span style=&quot;background: transparent; border: 0px; color: #95a5a6; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Purpose:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Demonstrates&amp;nbsp;how&amp;nbsp;to&amp;nbsp;use&amp;nbsp;comments.&lt;/span&gt;
&lt;span style=&quot;background: transparent; border: 0px; color: #95a5a6; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Increments&amp;nbsp;and&amp;nbsp;displays&amp;nbsp;a&amp;nbsp;number&amp;nbsp;in&amp;nbsp;the&amp;nbsp;main&amp;nbsp;loop.&lt;/span&gt;
&lt;span style=&quot;background: transparent; border: 0px; color: #95a5a6; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;
&lt;span style=&quot;background: transparent; border: 0px; color: #95a5a6; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Date:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;28&amp;nbsp;September&amp;nbsp;2014&lt;/span&gt;
&lt;span style=&quot;background: transparent; border: 0px; color: #95a5a6; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;
&lt;span style=&quot;background: transparent; border: 0px; color: #95a5a6; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Author:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;W.A.&amp;nbsp;Smith&lt;/span&gt;
&lt;span style=&quot;background: transparent; border: 0px; color: #95a5a6; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;*/&lt;/span&gt;
&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #95a5a6; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// use the serial port for printing the number&lt;/span&gt;
}

&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; count = 0;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #95a5a6; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// the number to print&lt;/span&gt;

&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(count++);  &lt;span style=&quot;background: transparent; border: 0px; color: #95a5a6; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// print and increment the number&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay&lt;/span&gt;(1000);              &lt;span style=&quot;background: transparent; border: 0px; color: #95a5a6; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// 1 second delay between printing&lt;/span&gt;
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
This sketch uses the increment operator and can be seen running in the video below.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe width=&quot;320&quot; height=&quot;266&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/O0Q27oScjlk/0.jpg&quot; src=&quot;https://www.youtube.com/embed/O0Q27oScjlk?feature=player_embedded&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Multi-line Comments&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Comments can be written on multiple lines when using the opening forward slash asterisk (&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;/*&lt;/strong&gt;) and closing asterisk forward slash (&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;*/&lt;/strong&gt;) as shown at the top of the sketch.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Any text comments can be written between the opening and closing of the comment and can span multiple lines. All text in the comment will be ignored by the compiler.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
This style of commenting can also be used on a single line, but must always be closed with the asterisk and forward slash as shown below.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay&lt;/span&gt;(1000);  &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;/* 1 second delay between printing */&lt;/span&gt;
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
There is an easier way to comment a single line of code, by using the single line comment, explained next.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Single Line Comments&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The double forward slash (&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;//&lt;/strong&gt;) is used to create a single line comment. All text to the right of the double forward slash on the same line will be a comment and will be ignored by the compiler.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The single line comment can be used on its own line or to the right of a program statement.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;//&amp;nbsp;the&amp;nbsp;delay&amp;nbsp;slows&amp;nbsp;down&amp;nbsp;the&amp;nbsp;printing&amp;nbsp;of&amp;nbsp;the&amp;nbsp;numbers&lt;/span&gt;
&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay&lt;/span&gt;(1000);  &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// 1 second delay between printing&lt;/span&gt;
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;br style=&quot;color: black; font-size: 16px;&quot; /&gt;&lt;br style=&quot;color: black; font-size: 16px;&quot; /&gt;&lt;br style=&quot;color: black; font-size: 16px;&quot; /&gt;&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
What Comments are Used For&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Comments are used to explain how parts of a sketch work, rather than explain the actual programming language that is being written.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
When you come back to a program or sketch that you wrote a month or a year ago, you may not remember why you wrote some part of the sketch a particular way. By writing comments in the sketch, you are making notes for yourself to help explain what you were doing when you first wrote the sketch.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Comments can also be arranged as a header section or comment block, like the multi-line comment block at the top of the example sketch. The block contains the name of the sketch, description or purpose of the sketch, date that it was written and the authors name. Comments can also contain references to any books, websites or other resources that were used when writing the sketch.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In short, comments and comment blocks communicate helpful information about the sketch for yourself and for other programmers who may also use the sketch.&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://moroccoele.blogspot.com/feeds/8266011844303229331/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2535795214191795882/8266011844303229331' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/8266011844303229331'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/8266011844303229331'/><link rel='alternate' type='text/html' href='http://moroccoele.blogspot.com/2017/02/increment-operator-and-commenting.html' title='Increment Operator and Commenting'/><author><name>zouhair</name><uri>http://www.blogger.com/profile/03215618839043737171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoyENEDs4YQxUpPwcjdLZADQluvebauDGIrDFFyFI-7Bq7JeSbIZoQ_U1sy2nRUarE5n8gI1mKu6PnZR7G5IEyk68FUqlhW0GNSbrXGp-gJA9x7p3NP2eLpcT0lebOdjr4ok-w8bcG58td/s72-c/1.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2535795214191795882.post-5821103341280439667</id><published>2017-02-11T01:37:00.003-08:00</published><updated>2017-02-11T01:37:56.707-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Arduino"/><title type='text'>Relational Operators</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Part 5 of the Arduino Programming Course&lt;/strong&gt;&lt;/div&gt;
&lt;div class=&quot;google_top_ad&quot; style=&quot;background: rgb(255, 255, 255); border: 0px; float: left; font-family: arial, helvetica, verdana, sans-serif; font-size: 16px; margin: 0px 10px 10px 0px; outline: 0px; padding: 0px 10px 0px 0px; vertical-align: baseline; width: 352.844px;&quot;&gt;
&lt;div class=&quot;clr_flt&quot; style=&quot;background: transparent; border: 0px; clear: both; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Relational operators test the relationship between values, for example is the number 7 greater than the number 5; or is the value that a variable holds less than 10.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The result of a comparison of two values by a relational operator will either be true or false, for example is the value contained in a variable equal to 8? The answer will either be true (it does hold the value 8) or false (it does not hold the value 8).&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In programming, true is represented by the value 1 and false is represented by the value 0. The example that follows will help to clarify this explanation of relational operators.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Relational Operator Example&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The following sketch uses the greater than (&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;gt;&lt;/strong&gt;) relational operator and the less than (&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;lt;&lt;/strong&gt;) relational operator to compare two numbers.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Is 7 greater than 5? &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(7 &amp;gt; 5);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Is 7 less than 5? &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(7 &amp;lt; 5);
}

&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {&lt;/pre&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;font-size: 0.8em;&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;The output of the above sketch is shown here.&lt;/pre&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjR-oEwYYnDx_BARZjef757iIUgYV4WtdRgBRljTeLvvJ-EqGGVm93K_PvpJrQenfEBttHKEIqDn4fRhZFR5vKrsUlUQS28TCYZXcMYuDpA-HwLVEa-ScmoUKGzadFoOmdqfL5b7hqu0lqj/s1600/a.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;151&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjR-oEwYYnDx_BARZjef757iIUgYV4WtdRgBRljTeLvvJ-EqGGVm93K_PvpJrQenfEBttHKEIqDn4fRhZFR5vKrsUlUQS28TCYZXcMYuDpA-HwLVEa-ScmoUKGzadFoOmdqfL5b7hqu0lqj/s320/a.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The first relational operator tests whether 7 is greater than 5:&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;7 &amp;gt; 5&lt;/strong&gt;&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
7 is greater than 5, so the output from this comparison is&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;true or 1&lt;/strong&gt;.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The second relational operator tests whether 7 is less than 5:&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;7 &amp;lt; 5&lt;/strong&gt;&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
7 is not less than 5, so the output from the comparison is&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;false or 0&lt;/strong&gt;.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Types of Relational Operators&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The Arduino programming language has 6 relational operators listed below.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Greater Than &amp;gt;&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
We have already seen the greater than relational operator working in the above example. Here is another example using the same operator to compare the contents of two variables.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; a = 2;
&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; b = 3;

&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(a &amp;gt; b);
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The relational operator asks the question&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Is a greater than b?&quot;&lt;/strong&gt;.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The result of the comparison will be&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;0&lt;/strong&gt;&amp;nbsp;(false) in this example because the value that variable&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;a&lt;/strong&gt;&amp;nbsp;contains is not greater than the value that variable&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;b&lt;/strong&gt;&amp;nbsp;contains.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Less Than &amp;lt;&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Here we use the less than relational operator to compare the contents of the same two variables.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; a = 2;
&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; b = 3;

&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(a &amp;lt; b);
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The relational operator asks the question&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Is a less than b?&quot;&lt;/strong&gt;.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The output of this sketch will be&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;1&lt;/strong&gt;&amp;nbsp;(true) because the value that variable&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;a&lt;/strong&gt;&amp;nbsp;contains is less than the value that variable&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;b&lt;/strong&gt;&amp;nbsp;contains.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Greater Than or Equal To &amp;gt;=&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
This operator acts in the same way as the greater than operator, but will also evaluate to true (1) if the two values being compared are equal to each other.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Less Than or Equal To &amp;lt;=&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
This operator will evaluate to true (1) if the value on the left of the operator is less than the value on the right of the operator; or if the two values are equal.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Equal To ==&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The equal to relational operator will only evaluate to true (1) if both values being compared are equal, otherwise it will evaluate to false (0).&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
It is easy to forget to use two equals signs (&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;==&lt;/strong&gt;) and use only one equals sign for the equal to relational operator. Using only one equals sign will cause the variable on the left of the operator to be assigned the value of the variable or constant on the right. If the value on the left is a constant, a compile error will occur if a single equals (&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;=&lt;/strong&gt;) is used instead of a double equals (&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;==&lt;/strong&gt;).&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Not Equal To !=&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The not equal to relational operator will only evaluate to true if the two values being compared to each other are not equal to each other, otherwise it will evaluate to false.&lt;/div&gt;
&lt;div class=&quot;clr_flt&quot; style=&quot;background: rgb(255, 255, 255); border: 0px; clear: both; font-family: arial, helvetica, verdana, sans-serif; font-size: 16px; font-weight: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Relational Operator Sketch&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The Arduino sketch below demonstrates relational operators.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 653.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; a = 2;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; b = 3;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Is a greater than b? &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(a &amp;gt; b);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Is a less than 25? &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(a &amp;lt; 25);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Is a greater than or equal to b? &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(a &amp;gt;= b);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;a&amp;nbsp;=&amp;nbsp;3;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Is a greater than or equal to b? &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(a &amp;gt;= b);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;a&amp;nbsp;=&amp;nbsp;4;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Is a greater than or equal to b? &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(a &amp;gt;= b);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Is a equal to b? &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(a == b);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;b&amp;nbsp;=&amp;nbsp;4;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Is a equal to b? &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(a == b);
&amp;nbsp;&amp;nbsp;
}

&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
This video shows the output produced from the above sketch after running it.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe width=&quot;320&quot; height=&quot;266&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/TbXvulAVpYI/0.jpg&quot; src=&quot;https://www.youtube.com/embed/TbXvulAVpYI?feature=player_embedded&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Copy this sketch and run it on your Arduino. Experiment with relational operators to make sure that you understand them.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;


&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Things to Note in the Sketch&lt;/h3&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Evaluating and Printing an Expression&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Something to note in the above sketches is that an expression is evaluated and printed in one statement. The result of the relational operator expression is not first saved to a variable and then printed.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
This can also be done with arithmetic operators as shown here:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; a = 2;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; b = 3;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;a + b = &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(a + b);
}

&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The output of the above sketch is shown here:&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgV1MRg5xSjt4lYO5CZaJQ5Yf-8_jRsZV_ivUw0f2v13vTrDjQhDppNPrM-gHFnuC63nxgD7hwciREFtk-EuCsLLGjWIrGAhoFGYtM7ohUVJ2k60pRqLj2Ld1fo9W55-DIDriyV9eYaBORw/s1600/b.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;128&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgV1MRg5xSjt4lYO5CZaJQ5Yf-8_jRsZV_ivUw0f2v13vTrDjQhDppNPrM-gHFnuC63nxgD7hwciREFtk-EuCsLLGjWIrGAhoFGYtM7ohUVJ2k60pRqLj2Ld1fo9W55-DIDriyV9eYaBORw/s320/b.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The expression&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;a + b&lt;/strong&gt;&amp;nbsp;is both evaluated (to get the value of 5) and printed in the same statement.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Confusing = and ==&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
As already noted, it is easy to forget the second equals sign when using the&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;equal to&lt;/strong&gt;&amp;nbsp;operator. The sketch below shows what can happen with this mistake.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; a = 2;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; b = 3;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;a == b: &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(a == b);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;a = b: &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(a = b);
}

&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The comparison of&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;a&lt;/strong&gt;&amp;nbsp;and&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;b&lt;/strong&gt;&amp;nbsp;in the expression&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;a == b&lt;/strong&gt;&amp;nbsp;is correct and evaluates to&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;0&lt;/strong&gt;&amp;nbsp;as expected.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
If the second equals sign is left off as shown in the second expression&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;a = b&lt;/strong&gt;, the assignment operator (&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;=&lt;/strong&gt;) is accidentally used instead of the equal to operator (&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;==&lt;/strong&gt;).&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
This causes&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;a&lt;/strong&gt;&amp;nbsp;to be assigned the value of&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;b&lt;/strong&gt;&amp;nbsp;which is&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;3&lt;/strong&gt;&amp;nbsp;and then 3 is printed out. A non-zero number will actually evaluate to true as we will see later in this course.&lt;/div&gt;
&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://moroccoele.blogspot.com/feeds/5821103341280439667/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2535795214191795882/5821103341280439667' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/5821103341280439667'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/5821103341280439667'/><link rel='alternate' type='text/html' href='http://moroccoele.blogspot.com/2017/02/relational-operators.html' title='Relational Operators'/><author><name>zouhair</name><uri>http://www.blogger.com/profile/03215618839043737171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjR-oEwYYnDx_BARZjef757iIUgYV4WtdRgBRljTeLvvJ-EqGGVm93K_PvpJrQenfEBttHKEIqDn4fRhZFR5vKrsUlUQS28TCYZXcMYuDpA-HwLVEa-ScmoUKGzadFoOmdqfL5b7hqu0lqj/s72-c/a.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2535795214191795882.post-6324908804508279661</id><published>2017-02-11T01:30:00.001-08:00</published><updated>2017-02-11T01:30:04.718-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="projects"/><title type='text'>Soldering for Beginners in Electronics</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Basic soldering for beginners in electronics. In this article, a pin header is soldered to a LCD which demonstrates how to solder a component to a PCB (printed circuit board).&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
This is a support article for the&amp;nbsp;&lt;a class=&quot;targetblank&quot; href=&quot;https://startingelectronics.org/beginners/start-electronics-now&quot; style=&quot;background: transparent; border-bottom-color: rgb(19, 78, 139); border-bottom-style: dotted; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #134e8b; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;&quot; target=&quot;_blank&quot;&gt;Start Electronics Now series of tutorials&lt;/a&gt;&amp;nbsp;where the pin header needs to be soldered to the LCD in order to plug it into a breadboard for connection to an Arduino.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
See the&amp;nbsp;&lt;a href=&quot;https://startingelectronics.org/beginners/tools/soldering-iron&quot; style=&quot;background: transparent; border-bottom-color: rgb(19, 78, 139); border-bottom-style: dotted; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #134e8b; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;&quot;&gt;article on soldering irons&lt;/a&gt;&amp;nbsp;before learning to solder.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Safety&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Take adequate precautions when soldering – soldering irons get hot and can burn you or your property&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Avoid breathing soldering fumes. The lead in solder is poisonous, so always wash your hands after handling solder or solder wire.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Read all safety instructions that are provided with your soldering iron, solder and other equipment.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Here are some precautions to take:&lt;/strong&gt;&lt;/div&gt;
&lt;ol style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin: 0px 0px 7px; outline: 0px; overflow: hidden; padding: 0px 0px 0px 1.8em; vertical-align: baseline;&quot;&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;To prevent getting burned, only touch or pick up the soldering iron by the handle, never touch the heating element or tip.&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Use a soldering iron stand to prevent burning your desktop or other property.&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Work in a well ventilated area. Use a fan to blow the solder fumes away or use a fume extractor.&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Remove all flammable materials and liquids from the soldering area.&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Wash your hands after handling solder as it contains lead.&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Always work in a well lit uncluttered area.&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Children are to be supervised by a competent adult when soldering.&lt;/li&gt;
&lt;/ol&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Starting Electronics and its authors will not accept responsibility for and damage sustained to yourself or others or any loss or damage to property from following these instructions. If at all unsure, do not proceed.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Preparation&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
To start soldering, you will need:&lt;/div&gt;
&lt;ol style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin: 0px 0px 7px; outline: 0px; overflow: hidden; padding: 0px 0px 0px 1.8em; vertical-align: baseline;&quot;&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;A soldering iron and stand with sponge.&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Solder.&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;The items to solder (e.g. component and wire or connector).&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;A suitable work area with enough light and ventilation.&lt;/li&gt;
&lt;/ol&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Wet the soldering iron sponge and then squeeze out the excess water. You will be using the sponge to clean the soldering iron tip.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Switch the soldering iron on or plug it into a power source so that it can start heating up. Place the soldering iron in a soldering iron stand while it is heating. Do not leave the soldering iron unattended while it is heating up or is still hot.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Soldering&lt;/h2&gt;
&lt;div class=&quot;clr_flt&quot; style=&quot;background: rgb(255, 255, 255); border: 0px; clear: both; font-family: arial, helvetica, verdana, sans-serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
To solder a component to a circuit board, first insert the component into the circuit board and then turn it over so that the pins of the inserted component can be seen.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Pick up the soldering iron and unwrap some solder from the solder reel. Heat the pin of the component and the circuit board pad for a second and then apply the solder to the pad and pin. Apply enough solder to make a good joint.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Use the damp sponge in the soldering iron stand to clean the tip of the soldering iron often.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The video below shows how to solder a pin header to a LCD display.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe width=&quot;320&quot; height=&quot;266&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/jsDf3n-Buo8/0.jpg&quot; src=&quot;https://www.youtube.com/embed/jsDf3n-Buo8?feature=player_embedded&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In the video, one pin of the header is soldered (or tacked) to the LCD display. The header is then checked that it is 90° to (at right angles to or square to) the LCD circuit board. The solder joint is reheated to melt the solder so that the header is shifted to 90° to the LCD board.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
After soldering one pin and squaring up the header, the pin at the opposite end of the header is soldered and then the header is checked one last time that it is square. The remainder of the pins are then soldered.&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://moroccoele.blogspot.com/feeds/6324908804508279661/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2535795214191795882/6324908804508279661' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/6324908804508279661'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/6324908804508279661'/><link rel='alternate' type='text/html' href='http://moroccoele.blogspot.com/2017/02/soldering-for-beginners-in-electronics.html' title='Soldering for Beginners in Electronics'/><author><name>zouhair</name><uri>http://www.blogger.com/profile/03215618839043737171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/jsDf3n-Buo8/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2535795214191795882.post-148792646793811347</id><published>2017-02-11T01:28:00.002-08:00</published><updated>2017-02-11T01:28:12.201-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="projects"/><title type='text'>First Steps in Using a Multimeter Part 3</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
A multimeter can be used for continuity testing. Continuity testing is done to check if there is a break in a wire or track on a circuit board (open circuit). Continuity testing can also check whether a wire or track is shorted to another wire or track (short circuit).&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
When the continuity function is used on a multimeter, the leads of the multimeter are placed on either end of a wire or track, the multimeter will make an audible sound if the wire or track is not broken, i.e. it is continuous. The multimeter acts as a buzzer circuit and the leads act as a switch. When the leads are touched together or on either ends of a conductor, the buzzer circuit is completed and the buzzer sounds.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The videos below show continuity testing on various items. A description of what is being done follows each video.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;b&gt;BASIC CONTINIUITY TESTING&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe width=&quot;320&quot; height=&quot;266&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/arKUmGaRvIM/0.jpg&quot; src=&quot;https://www.youtube.com/embed/arKUmGaRvIM?feature=player_embedded&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Selecting the Continuity Function&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
To use the multimeter continuity function, switch the multimeter dial to the continuity test function. Touch the multimeter leads together and you should hear an audible &quot;beep&quot; sound. It is best to always touch the leads together and check for the beep before testing. This is done so that you know that the continuity function is working.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Performing the Continuity Test&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In the video, a piece of stripboard is tested to see if a strip is unbroken and also to see that it is not shorted to one of the adjacent strips (one of the strips next to it).&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
A second multimeter is used to do the same stripboard test. This multimeter has a single dial setting for both the diode test and the continuity test.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
A third multimeter (which is a cheap one) does not have an audible continuity tester. In this case, the diode tester is used and continuity is shown on the multimeter&#39;s display.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Wires from a cable are then tested for continuity.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Finally a printed circuit board (PCB) is tested for continuity of its tracks and to test that tracks are not shorted to each other. Normally every track would be tested, but only a few are checked in this video for demonstration purposes.&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://moroccoele.blogspot.com/feeds/148792646793811347/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2535795214191795882/148792646793811347' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/148792646793811347'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/148792646793811347'/><link rel='alternate' type='text/html' href='http://moroccoele.blogspot.com/2017/02/first-steps-in-using-multimeter-part-3.html' title='First Steps in Using a Multimeter Part 3'/><author><name>zouhair</name><uri>http://www.blogger.com/profile/03215618839043737171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/arKUmGaRvIM/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2535795214191795882.post-4205207953176735858</id><published>2017-02-11T01:25:00.004-08:00</published><updated>2017-02-11T01:25:44.676-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="projects"/><title type='text'>First Steps in Using a Multimeter Part 2</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Before measuring current, the positive (red) lead of the multimeter must usually be unplugged from it&#39;s normal connector in the multimeter and then plugged into a separate connector in the multimeter that is marked A or mA. This is not always the case, some cheaper meters may have the volts, mill-amps and ohms on one connector and amps on a separate connector.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In this video, two different multimeters are used to measure current in the same circuit. The first multimeter is a cheap one that does not require the red lead to be plugged into a separate connector when measuring mill-amps (mA). The second meter does require the red lead to be plugged into a separate connector to measure mill-amps.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe width=&quot;320&quot; height=&quot;266&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/x89thdDR1KI/0.jpg&quot; src=&quot;https://www.youtube.com/embed/x89thdDR1KI?feature=player_embedded&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The Circuit Under Test&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The circuit in the video in which current is being measured is a simple LED circuit that consists of a LED in series with a resistor. This circuit is the same circuit that is used in&amp;nbsp;&lt;a href=&quot;https://startingelectronics.org/beginners/start-electronics-now/tut1-breadboard-circuits&quot; style=&quot;background: transparent; border-bottom-color: rgb(19, 78, 139); border-bottom-style: dotted; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #134e8b; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;&quot;&gt;tutorial 1&lt;/a&gt;.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Precaution&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
It is very important to realise that when a multimeter is set to the amps or mill-maps scale, and the red lead plugged into the correct socket in the multimeter, that the two leads of the multimeter are now like a single piece of wire. Touching the leads to the two terminals of a battery must never be done as this will short out the battery and is the same as taking a single piece of wire and connecting it across the battery terminals.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In the same way, when the multimeter is set to amps or milli-amps range, it must not be used to measure across any component in a circuit. This would be the same as shorting the component out with a piece of wire.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Taking a Current Measurement&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
To measure the current flowing in a circuit, the circuit must be broken and the multimeter inserted in the break to then complete the circuit again. In this way the multimeter in current mode forms part of the circuit.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In the video, the current flows from the battery terminal through the multimeter, then through the LED, through the resistor and back to the opposite battery terminal.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Series and Parallel Measurement&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The multimeter on the current setting (which makes it into an ammeter) is said to be connected in series in the circuit.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Voltage measurements are made in parallel or across a battery or component in a circuit.&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://moroccoele.blogspot.com/feeds/4205207953176735858/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2535795214191795882/4205207953176735858' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/4205207953176735858'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/4205207953176735858'/><link rel='alternate' type='text/html' href='http://moroccoele.blogspot.com/2017/02/first-steps-in-using-multimeter-part-2.html' title='First Steps in Using a Multimeter Part 2'/><author><name>zouhair</name><uri>http://www.blogger.com/profile/03215618839043737171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/x89thdDR1KI/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2535795214191795882.post-7362169878410681057</id><published>2017-02-11T01:24:00.003-08:00</published><updated>2017-02-11T01:24:46.104-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="projects"/><title type='text'>First Steps in Using a Multimeter Part 1</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 15.568px;&quot;&gt;A multimeter is a measuring instrument that anyone involved in electronics will need to use at some stage. A multimeter can be used to measure voltage, current, resistance, continuity and other parameters.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 15.568px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Measuring DC Voltage and Resistance&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The video below shows a multimeter being used to measure voltage from batteries (DC (direct current) voltage) and the resistance of some resistors.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe width=&quot;320&quot; height=&quot;266&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/vFYCt91Xuh8/0.jpg&quot; src=&quot;https://www.youtube.com/embed/vFYCt91Xuh8?feature=player_embedded&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Measuring DC Voltage&lt;/h3&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Selecting the DC Voltage Range&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
To measure DC voltage using a multimeter, simply turn the selector dial on the multimeter to the DC voltage setting. On an auto-ranging multimeter such as the one shown in the video, there will only be one DC voltage selection on the dial.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
A multimeter that is not auto-ranging will have a selection of voltages on the dial that can be chosen, e.g. 2V, 20V, 200V, 1000V. On this type of multimeter, start by selecting the highest voltage on the dial and then turn down to a lower voltage if the voltage measured is seen to be low. If you are measuring a single battery cell and you know that it is a 1.2V or 1.5V cell, then you can start by setting the multimeter dial to 2V or 20V.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Taking a Measurement&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
After selecting DC voltage on the multimeter dial, use the two probes to measure across the battery terminals. The black probe should be used on the negative terminal of the battery and must be connected to the COM connection on the multimeter. The red probe should be used on the positive terminal of the battery and connected to the connection on the multimeter that is marked V. This connection may have other symbols marking it as well, such as the ohm symbol (Ω).&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
After applying the probes to the battery, the voltage of the battery will be shown on the multimeter display.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Polarity&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
If the red and black multimeter probes are connected the wrong way around to the battery (i.e. black on positive and red on negative) then a digital multimeter will show a negative sign next to the voltage reading on the display.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
On a digital multimeter, it does not matter if the leads are reversed when measuring voltage. Getting the leads the right way around (correct polarity – red on positive and black on negative) does matter on the old analog multimeters (the type with the indicator needle). An analog (or analogue) multimeter can be damaged if the polarity is reversed on the leads.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Measurement Results&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In the video, batteries made up of 1.2V rechargeable cells are used. The first one measured has six cells, so the voltage should be about 1.2V × 6 = 7.2V. The second battery measured contains two cells or 1.2V × 2 = 2.4V. A single 1.2V cell is measured last.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
When 1.2V batteries are fully charged, they will have a voltage of slightly more than 1.2V. This can be seen by the measurements taken in the video.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;br style=&quot;color: black; font-size: 16px;&quot; /&gt;&lt;/div&gt;
&lt;div class=&quot;clr_flt&quot; style=&quot;background: rgb(255, 255, 255); border: 0px; clear: both; font-family: arial, helvetica, verdana, sans-serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;br style=&quot;color: black; font-size: 16px;&quot; /&gt;&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Measuring Resistance&lt;/h3&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Selecting the Resistance Range (Ohms – Ω)&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
To measure resistance, using a multimeter, turn the multimeter dial to the ohm marking. As for measuring voltage on an auto-ranging multimeter, there will be only one dial setting for measuring resistance.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
On a multimeter that is not auto-ranging, there will be a number of different ranges marked on the multimeter dial, e.g. 200, 2k, 20k, 200k, 2M, 20M. If the approximate range of the resistance to be measured is unknown, then always start measuring with the biggest range, e.g. 20M. If the value measured on this range is seen to be small, then the dial can be turned down to a smaller range.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Precaution&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Never measure resistance on a live circuit – i.e. a circuit that has power switched on to it.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Taking the Resistance Measurement&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Apply the tips of the multimeter probes across the resistance to be measured and read the resistance value on the multimeter display.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Measurement Results&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The resistors measured in the video all have a 5% tolerance. This means that the values of the resistors could be between the 5% more or 5% less than the stated value of the resistor that you would read by decoding the resistor colour code&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://moroccoele.blogspot.com/feeds/7362169878410681057/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2535795214191795882/7362169878410681057' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/7362169878410681057'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/7362169878410681057'/><link rel='alternate' type='text/html' href='http://moroccoele.blogspot.com/2017/02/first-steps-in-using-multimeter-part-1.html' title='First Steps in Using a Multimeter Part 1'/><author><name>zouhair</name><uri>http://www.blogger.com/profile/03215618839043737171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/vFYCt91Xuh8/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2535795214191795882.post-3837660725473805181</id><published>2017-02-10T07:18:00.002-08:00</published><updated>2017-02-10T07:18:24.806-08:00</updated><title type='text'>Start Electronics Now</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The best way to start electronics as a hobby is to start building circuits. You do not need to know how the circuits work or what the parts do at first.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
This series of tutorials and articles teaches electronics to beginners using an electronic breadboard that allows easy assembly and disassembly of electronic circuits.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Electronic parts can be used and then reused to build different circuits on the breadboard. Circuits are built by plugging parts into the breadboard and joining them using single-strand wire.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjF2DdHBJM07T2-DjxosUapoMbyShcLmOqXbc6f1JDcF41XZtsIsHCKDqiZRhgAIyuQpu6nJvsp7V5gYAohPmclAnA4PuSVN3VT5kJmZW4ccAshVvy_xc4KCgqJD3-iYUlXoVJQjKALoWl_/s1600/8.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;128&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjF2DdHBJM07T2-DjxosUapoMbyShcLmOqXbc6f1JDcF41XZtsIsHCKDqiZRhgAIyuQpu6nJvsp7V5gYAohPmclAnA4PuSVN3VT5kJmZW4ccAshVvy_xc4KCgqJD3-iYUlXoVJQjKALoWl_/s320/8.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-size: 15.568px;&quot;&gt;This is how a circuit is built on an electronic breadboard by plugging parts into it:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVFok-gTSio2rbsh8EDrXx5l1ujOMZ7XkY6LF5VqSX6cR9M-uoYOUdybU0mP-8kptIxLX0yt1UCN5RMjilcxysflmIfSOCzVEOxuaTAuA9j4sUJgGjEdwbIGcPou7iE42ffoQhReZD7w9S/s1600/9.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;263&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVFok-gTSio2rbsh8EDrXx5l1ujOMZ7XkY6LF5VqSX6cR9M-uoYOUdybU0mP-8kptIxLX0yt1UCN5RMjilcxysflmIfSOCzVEOxuaTAuA9j4sUJgGjEdwbIGcPou7iE42ffoQhReZD7w9S/s320/9.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-size: 15.568px;&quot;&gt;This video shows how to plug parts into a breadboard to build a circuit. You will learn how to use a breadboard in the first tutorial of this series.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe width=&quot;320&quot; height=&quot;266&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/IhJ2k9HPB0k/0.jpg&quot; src=&quot;https://www.youtube.com/embed/IhJ2k9HPB0k?feature=player_embedded&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
This article will show you what you will need to get started. At the end of the article, you will know what to buy to be able to follow the beginners tutorials.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Before starting electronics, you will need:&lt;/div&gt;
&lt;ol style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin: 0px 0px 7px; outline: 0px; overflow: hidden; padding: 0px 0px 0px 1.8em; vertical-align: baseline;&quot;&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Some tools&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Some electronic parts (components)&lt;/li&gt;
&lt;/ol&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
See what tools you will need to start electronics in the next part of this article.&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://moroccoele.blogspot.com/feeds/3837660725473805181/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2535795214191795882/3837660725473805181' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/3837660725473805181'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/3837660725473805181'/><link rel='alternate' type='text/html' href='http://moroccoele.blogspot.com/2017/02/start-electronics-now.html' title='Start Electronics Now'/><author><name>zouhair</name><uri>http://www.blogger.com/profile/03215618839043737171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjF2DdHBJM07T2-DjxosUapoMbyShcLmOqXbc6f1JDcF41XZtsIsHCKDqiZRhgAIyuQpu6nJvsp7V5gYAohPmclAnA4PuSVN3VT5kJmZW4ccAshVvy_xc4KCgqJD3-iYUlXoVJQjKALoWl_/s72-c/8.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2535795214191795882.post-3845768191035863840</id><published>2017-02-10T07:14:00.001-08:00</published><updated>2017-02-10T07:14:06.456-08:00</updated><title type='text'>Arduino MEGA 24 LED Knight Rider Display</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
built on a breadboard using 24 LEDs.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
An Arduino MEGA 2560 is used to directly drive the LEDs from 24 of the Arduino&#39;s pins. An Arduino Uno can not be used to drive the LEDs directly because it has too few pins, although it would be possible to expand the number of outputs on an Arduino Uno using four&amp;nbsp;&lt;a href=&quot;https://startingelectronics.org/beginners/start-electronics-now/tut18-two-wire-arduino-knight-rider/&quot; style=&quot;background: transparent; border-bottom-color: rgb(19, 78, 139); border-bottom-style: dotted; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #134e8b; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;&quot;&gt;PCF8574 I/O expander ICs&lt;/a&gt;.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The circuit is pretty simple as it is just an LED and series resistor connected to each pin and repeated 24 times. Pins 30 to 51 are used on the Arduino MEGA.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The video below shows the circuit operating.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe width=&quot;320&quot; height=&quot;266&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/QzAmYOCD1HY/0.jpg&quot; src=&quot;https://www.youtube.com/embed/QzAmYOCD1HY?feature=player_embedded&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
The Circuit Diagram&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The 24 LED knight rider circuit diagram is shown below. Only the first two and last two LEDs are shown in the circuit as the other LEDs are just a repetition of the LED and series resistor connected to the pins in sequential order.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;img alt=&quot;24 LED Knight Rider Display Circuit&quot; height=&quot;506&quot; src=&quot;https://startingelectronics.org/beginners/circuits/MEGA-24-LED-knight-rider/Knight-Rider-with-24-LEDs.png&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; color: black; font-size: 16px; height: auto; margin: 0px; max-width: 100%; outline: 0px; padding: 0px; vertical-align: baseline;&quot; width=&quot;500&quot; /&gt;&lt;span style=&quot;color: black; font-size: 16px;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;pic_caption&quot; style=&quot;background: rgb(255, 255, 255); border: 0px; color: blue; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.8em; font-weight: bold; line-height: 16.64px; margin-bottom: 16px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
24 LED Knight Rider Display Circuit using the Arduino MEGA&lt;/div&gt;
&lt;div class=&quot;clr_flt&quot; style=&quot;background: rgb(255, 255, 255); border: 0px; clear: both; font-family: arial, helvetica, verdana, sans-serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Arduino Knight Rider Sketch&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The code for the Arduino Knight Rider display is shown here.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 653.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; delay_ms = 50;

&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; i;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/span&gt; (i = 30; i &amp;lt;= 53; i++) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;pinMode&lt;/span&gt;(i, &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;OUTPUT&lt;/span&gt;);    &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// set pins as outputs&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(i, &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;LOW&lt;/span&gt;);  &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// switch the output pins off&lt;/span&gt;
&amp;nbsp;&amp;nbsp;}
}

&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;boolean&lt;/span&gt; forward = &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;true&lt;/span&gt;;    &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// LED direction flag&lt;/span&gt;
&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; pin_num;

&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;if&lt;/span&gt; (forward) {  &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// LEDs left to right&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/span&gt; (pin_num = 30; pin_num &amp;lt;= 53; pin_num++) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(pin_num, &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;HIGH&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay&lt;/span&gt;(delay_ms);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(pin_num, &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;LOW&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;forward&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;false&lt;/span&gt;;
&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;else&lt;/span&gt; {          &lt;span style=&quot;background: transparent; border: 0px; color: #7e7e7e; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// LEDs right to left&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;for&lt;/span&gt; (pin_num = 53; pin_num &amp;gt;= 30; pin_num--) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(pin_num, &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;HIGH&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay&lt;/span&gt;(delay_ms);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;digitalWrite&lt;/span&gt;(pin_num, &lt;span style=&quot;background: transparent; border: 0px; color: #006699; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;LOW&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;forward&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #cc6600; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;true&lt;/span&gt;;
&amp;nbsp;&amp;nbsp;}
}

&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The speed of the display can be set by changing the value of&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay_ms&lt;/b&gt;&amp;nbsp;at the top of the sketch.&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://moroccoele.blogspot.com/feeds/3845768191035863840/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2535795214191795882/3845768191035863840' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/3845768191035863840'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/3845768191035863840'/><link rel='alternate' type='text/html' href='http://moroccoele.blogspot.com/2017/02/arduino-mega-24-led-knight-rider-display.html' title='Arduino MEGA 24 LED Knight Rider Display'/><author><name>zouhair</name><uri>http://www.blogger.com/profile/03215618839043737171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/QzAmYOCD1HY/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2535795214191795882.post-1297725600576445844</id><published>2017-02-10T07:09:00.001-08:00</published><updated>2017-02-10T07:09:38.891-08:00</updated><title type='text'>Arithmetic Operators</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Part 4 of the Arduino Programming Course&lt;/strong&gt;&lt;/div&gt;
&lt;div class=&quot;google_top_ad&quot; style=&quot;background: rgb(255, 255, 255); border: 0px; float: left; font-family: arial, helvetica, verdana, sans-serif; font-size: 16px; margin: 0px 10px 10px 0px; outline: 0px; padding: 0px 10px 0px 0px; vertical-align: baseline; width: 352.844px;&quot;&gt;
&lt;div class=&quot;clr_flt&quot; style=&quot;background: transparent; border: 0px; clear: both; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The Arduino can do mathematics for us. In this part of the course, we look at how to do addition, subtraction, multiplication, division, and find a remainder.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Below, five arithmetic operators are described and then all put into a sketch to demonstrate how they work on the Arduino.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Addition&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
To add numbers on the Arduino, we use the addition operator (&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;+&lt;/strong&gt;).&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The example below shows how to add two numbers together.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; a = 2;
&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; b = 7;
&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; sum;

sum&amp;nbsp;=&amp;nbsp;a&amp;nbsp;+&amp;nbsp;b;
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In the above code, three variables are defined. Variables&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;a&lt;/strong&gt;&amp;nbsp;and&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;b&lt;/strong&gt;&amp;nbsp;are each assigned a value when they are defined.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;sum&lt;/strong&gt;&amp;nbsp;variable is defined, but not initialized, so contains any random number. We will use this variable to store the result of the addition calculation, so the random value that&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;sum&lt;/strong&gt;&amp;nbsp;contains will be overwritten when we put the addition result (or sum) into it.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
After the statement shown below has been executed,&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;sum&lt;/strong&gt;&amp;nbsp;will contain the value&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;9&lt;/strong&gt;&amp;nbsp;i.e. the result of the addition of variable&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;a&lt;/strong&gt;&amp;nbsp;and&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;b&lt;/strong&gt;.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;sum&amp;nbsp;=&amp;nbsp;a&amp;nbsp;+&amp;nbsp;b;
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
We can also add two constant values and store the result in a variable as shown below.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; sum;

sum&amp;nbsp;=&amp;nbsp;2&amp;nbsp;+&amp;nbsp;10;
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The result stored in&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;sum&lt;/strong&gt;&amp;nbsp;after execution of the addition statement will be&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;12&lt;/strong&gt;&amp;nbsp;in this example.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Constant values and variables can also be added together and the result stored in a variable as shown here.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; a = 3;
&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; sum;

sum&amp;nbsp;=&amp;nbsp;a&amp;nbsp;+&amp;nbsp;24;
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
After execution of the addition,&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;sum&lt;/strong&gt;&amp;nbsp;will contain&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;27&lt;/strong&gt;.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The remaining arithmetic operators can also operate on constant values, variables and a mixture of both.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Subtraction&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The subtraction operator subtracts one number from another using the minus sign (&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;-&lt;/strong&gt;) as the following example shows.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; result;

result&amp;nbsp;=&amp;nbsp;10&amp;nbsp;- 2;
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The result of this calculation will be&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;8&lt;/strong&gt;&amp;nbsp;and will be stored in the&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;result&lt;/strong&gt;&amp;nbsp;variable.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Multiplication&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Multiplication is done by using the multiplication operator (&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;*&lt;/strong&gt;).&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; result;

result&amp;nbsp;=&amp;nbsp;4&amp;nbsp;*&amp;nbsp;3;
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The result of the above calculation will be&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;12&lt;/strong&gt;&amp;nbsp;and will be stored in the&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;result&lt;/strong&gt;&amp;nbsp;variable.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Division&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The division operator (&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;/&lt;/strong&gt;) is used to perform division in the Arduino.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; result;

result&amp;nbsp;=&amp;nbsp;12&amp;nbsp;/&amp;nbsp;3;
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The result of the above calculation is 4.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Integers vs. Floating Point&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
So far we have only been using integer values to perform arithmetic. If the result of a division is not an integer (or whole number), but contains a fraction part, the fraction part will be discarded if the result is stored in an integer variable.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The following examples will demonstrate what happens when a result with a fractional part is stored in an integer and then a floating point variable.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; result;

result&amp;nbsp;=&amp;nbsp;5&amp;nbsp;/&amp;nbsp;4;
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The result will be&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;1&lt;/strong&gt;&amp;nbsp;because the fraction is discarded when the result is stored in the integer variable&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;result&lt;/strong&gt;.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The same calculation, but this time defining&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;result&lt;/strong&gt;&amp;nbsp;as a floating point variable (&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;float&lt;/strong&gt;).&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;float&lt;/span&gt; result;

result&amp;nbsp;=&amp;nbsp;5.0&amp;nbsp;/&amp;nbsp;4.0;
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The result now contained in the&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;result&lt;/strong&gt;&amp;nbsp;variable is&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;1.25&lt;/strong&gt;.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
When using constant values in calculations that store the result in a floating point variable, we use a decimal point and a zero for whole numbers, i.e. 5.0 instead of 5 on its own.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Remainder (Modulo Division)&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The remainder operator (or modulo operator) is used to find the remainder after the division of two numbers. The percentage sign (&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;%&lt;/strong&gt;) is used as the modulo operator.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; result;

result&amp;nbsp;=&amp;nbsp;11&amp;nbsp;%&amp;nbsp;4;
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The result of this calculation will be the remainder of 11 divided by 4 which is&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;3&lt;/strong&gt;&amp;nbsp;(4 goes into 11 twice leaving a remainder of 3).&lt;/div&gt;
&lt;br style=&quot;background-color: white; font-family: arial, helvetica, verdana, sans-serif; font-size: 16px;&quot; /&gt;&lt;br style=&quot;background-color: white; font-family: arial, helvetica, verdana, sans-serif; font-size: 16px;&quot; /&gt;&lt;br style=&quot;background-color: white; font-family: arial, helvetica, verdana, sans-serif; font-size: 16px;&quot; /&gt;&lt;br /&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Arithmetic Sketch&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The following sketch called&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;arithmetic&lt;/b&gt;&amp;nbsp;demonstrates all of the above arithmetic operators.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Load the sketch to your Arduino and try it out. Also add the examples from above that are not in the sketch, such as mixing constant values and variables.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 653.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; a = 2;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; b = 7;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; result;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;float&lt;/span&gt; result_fl;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Addition (a + b): &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;result&amp;nbsp;=&amp;nbsp;a&amp;nbsp;+&amp;nbsp;b;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(result);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Subtraction (10 - 2): &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;result&amp;nbsp;=&amp;nbsp;10&amp;nbsp;-&amp;nbsp;2;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(result);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Multiplication (4 * 3): &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;result&amp;nbsp;=&amp;nbsp;4&amp;nbsp;*&amp;nbsp;3;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(result);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Int Division (5 / 4): &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;result&amp;nbsp;=&amp;nbsp;5&amp;nbsp;/&amp;nbsp;4;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(result);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Float Division (5.0 / 4.0): &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;result_fl&amp;nbsp;=&amp;nbsp;5.0&amp;nbsp;/&amp;nbsp;4.0;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(result_fl);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Remainder (11 % 4): &quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;result&amp;nbsp;=&amp;nbsp;11&amp;nbsp;%&amp;nbsp;4;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(result);
}

&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
This video shows the above sketch running.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe width=&quot;320&quot; height=&quot;266&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/ZURHmr3wiOg/0.jpg&quot; src=&quot;https://www.youtube.com/embed/ZURHmr3wiOg?feature=player_embedded&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Comments on the Sketch&lt;/h3&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
print() Function&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The sketch contains a mix of&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;print()&lt;/strong&gt;&amp;nbsp;and&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println()&lt;/strong&gt;&amp;nbsp;functions. print() is called when the invisible cursor must stay on the same line so text printed in the println() statement that follows will be printed on the same line as well.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
println() Function&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
println() is used when text must be printed and then the invisible cursor moved to the next line so that the next print() statement will print text on a new line.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Floating Point Variable&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
A separate&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;result_fl&lt;/strong&gt;&amp;nbsp;variable was defined to hold the result of the floating point calculation.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Integer Variable&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The integer variable&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;result&lt;/strong&gt;&amp;nbsp;is reused many times during the sketch. The important thing is to display its result before placing the result of the next calculation into it.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Constants and Variables&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
We looked at variables in the last part of this course.&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Constants&lt;/strong&gt;&amp;nbsp;are numbers that remain constant throughout a sketch – i.e. they never change.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Examples of constants are the numbers that are used directly in a calculation and are not assigned to a variable, e.g. sum = 2 + 3 contains the constants 2 and 3.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Constants do not have a name and their values can not be changed when the sketch is running.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Floating Point Arithmetic&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Although not shown in the above examples, addition, subtraction and multiplication can also be done on floating point values.&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://moroccoele.blogspot.com/feeds/1297725600576445844/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2535795214191795882/1297725600576445844' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/1297725600576445844'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/1297725600576445844'/><link rel='alternate' type='text/html' href='http://moroccoele.blogspot.com/2017/02/arithmetic-operators.html' title='Arithmetic Operators'/><author><name>zouhair</name><uri>http://www.blogger.com/profile/03215618839043737171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/ZURHmr3wiOg/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2535795214191795882.post-9144414207910441523</id><published>2017-02-10T07:04:00.002-08:00</published><updated>2017-02-10T07:04:53.276-08:00</updated><title type='text'>Variables</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Part 3 of the Arduino Programming Course&lt;/strong&gt;&lt;/div&gt;
&lt;div class=&quot;google_top_ad&quot; style=&quot;background: rgb(255, 255, 255); border: 0px; float: left; font-family: arial, helvetica, verdana, sans-serif; font-size: 16px; margin: 0px 10px 10px 0px; outline: 0px; padding: 0px 10px 0px 0px; vertical-align: baseline; width: 352.844px;&quot;&gt;
&lt;div class=&quot;clr_flt&quot; style=&quot;background: transparent; border: 0px; clear: both; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
A variable is used in programming to store a value that may change during the life of the program (or sketch).&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Memory is set aside for storing the variable and the variable is given a name which allows it to be accessed in the sketch.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
One example of a variable is if you were to write a sketch that keeps the total of a teams score in a sports match. The value that the variable is holding (i.e. the teams score) would be displayed on a screen while the sports match is being played. As the score increases, the value that the variable holds will be increased and the display on the screen would be updated showing the new value that the score variable now holds.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In this example, the score value may change several times during the match and the time that the sketch is running. It is therefore variable as opposed to a fixed or constant value.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Using a Variable&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The following sketch called&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;variables&lt;/b&gt;&amp;nbsp;demonstrates the use of a variable. Load this sketch to your Arduino and open the serial monitor window to see the output of the sketch.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; count;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;count&amp;nbsp;=&amp;nbsp;0;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(count);
&amp;nbsp;&amp;nbsp;count&amp;nbsp;=&amp;nbsp;1;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(count);
&amp;nbsp;&amp;nbsp;count&amp;nbsp;=&amp;nbsp;2;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(count);
}

&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
}&lt;/pre&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;This video shows the sketch running.&lt;/pre&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe width=&quot;320&quot; height=&quot;266&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/ra1432sFxQc/0.jpg&quot; src=&quot;https://www.youtube.com/embed/ra1432sFxQc?feature=player_embedded&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Variable Definition&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The following statement from the above sketch is a variable&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;definition&lt;/em&gt;&amp;nbsp;as it defines the variable type and name:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; count;
&lt;/pre&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Variable Type&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
In the above example, the variable type is&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/strong&gt;. This means that the variable can hold an&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;integer&lt;/strong&gt;&amp;nbsp;value.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
An integer is a whole number – i.e. not a fraction. For example, the following numbers are integers 2, 5, 0, 100, 1024, -32, etc.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Variable Name&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The above variable has been given the name&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;count&lt;/strong&gt;. This variable can now be referenced or used in the sketch by using the name &quot;count&quot;.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
By giving the variable a type and name, space is made available in memory for this variable.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Using the Variable in a Sketch&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
After a variable has been defined, it can be assigned a value and the value of the variable can be displayed in the serial monitor window.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
In the following two statements, the&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;count&lt;/strong&gt;&amp;nbsp;variable is first assigned a value of 0 and then the value that this variable is holding is sent out of the serial port for display in the serial monitor window.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;count&amp;nbsp;=&amp;nbsp;0;
&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(count);
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
In the sketch, the same lines of code are repeated, but each time the&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;count&lt;/strong&gt;&amp;nbsp;variable is assigned a different value.&lt;/div&gt;
&lt;div class=&quot;clr_flt&quot; style=&quot;background: rgb(255, 255, 255); border: 0px; clear: both; font-family: arial, helvetica, verdana, sans-serif; font-size: 16px; font-weight: normal; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Types of Variables&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The integer (int) variable type is only one type of variable. An example of a different variable type is a&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;float&lt;/strong&gt;&amp;nbsp;or floating point variable.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
A floating point variable is used to store a number that contains a fraction, e.g. 1.45, 99.99, 362.5634, -200.21, etc.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
A floating point variable is defined in the same way as an integer variable, except that the&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;float&lt;/strong&gt;&amp;nbsp;keyword is used instead of&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/strong&gt;&amp;nbsp;as shown in the example below.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;float&lt;/span&gt; average;
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
This floating point variable can now be assigned a floating point value e.g.:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;average&amp;nbsp;=&amp;nbsp;1.2;
&lt;/pre&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Printing a Float Value&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
To print or send a floating point value to the Arduino serial monitor window, the&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println()&lt;/strong&gt;&amp;nbsp;function can be used.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
A second parameter can be passed to the println() function to specify the number of decimal places that must be printed as shown in the&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;floats&lt;/b&gt;&amp;nbsp;sketch below.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;float&lt;/span&gt; average;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;average&amp;nbsp;=&amp;nbsp;12.3299;
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(average);

&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(average, 4);
}

&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The output of the above sketch is shown here.&lt;/div&gt;
&lt;img alt=&quot;Printing floating point values in the serial monitor window.&quot; height=&quot;172&quot; src=&quot;https://startingelectronics.org/software/arduino/learn-to-program-course/03-variables/printing-floats.jpg&quot; style=&quot;background: rgb(255, 255, 255); border: 0px; font-family: arial, helvetica, verdana, sans-serif; font-size: 16px; font-weight: normal; height: auto; margin: 0px; max-width: 100%; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot; width=&quot;327&quot; /&gt;&lt;span style=&quot;background-color: white; font-family: arial, helvetica, verdana, sans-serif; font-size: 16px; font-weight: normal; white-space: normal;&quot;&gt;&lt;/span&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The above sketch assigns a value of 12.3299 to the&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;average&lt;/strong&gt;&amp;nbsp;floating point variable. When the value of the variable is sent to the serial monitor window, we can see that println() automatically rounds the number off to two decimal places.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
The second time that println() is used to send the value of the variable to the serial monitor window, the number of decimal places is specified as&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;4&lt;/strong&gt;. This is done by passing a second parameter value of 4 to the println() function.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Other Variable Types&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Other types of variables that are available can be seen in the&amp;nbsp;&lt;a class=&quot;targetblank&quot; href=&quot;http://arduino.cc/en/Reference/HomePage&quot; style=&quot;background: transparent; border-bottom-color: rgb(19, 78, 139); border-bottom-style: dotted; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #134e8b; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;&quot; target=&quot;_blank&quot;&gt;Arduino language reference&lt;/a&gt;&amp;nbsp;under the&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Variables&lt;/strong&gt;&amp;nbsp;heading.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
On this course, each variable type will be introduced and explained at the appropriate time.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Naming Variables&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Variables can be given any name that you like, so long as it sticks to the rules set out below. It is best to give variables meaningful names that help you and others to understand the sketch better, e.g.&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;score_total&lt;/strong&gt;&amp;nbsp;would be a good variable name for a variable that is storing the running total of a score in a sports match.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Variable Naming Rules&lt;/h3&gt;
&lt;ul style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin: 0px 0px 7px; outline: 0px; overflow: hidden; padding: 0px 0px 0px 1.8em; vertical-align: baseline; white-space: normal;&quot;&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Variables can consist of any letters (a to z and A to Z)&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Variables can contain the numbers 0 to 9, but may not start with a number, e.g.&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;3var&lt;/strong&gt;&amp;nbsp;is not allowed, but&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;var3&lt;/strong&gt;&amp;nbsp;is allowed&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Variables may not have the same names as Arduino language keywords, e.g. you can not have a variable named&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/strong&gt;&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Variables must have unique names i.e. you can not have two variables with the same name&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Variable names are case sensitive, so&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Count&lt;/strong&gt;&amp;nbsp;and&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;count&lt;/strong&gt;&amp;nbsp;are two different variables&lt;/li&gt;
&lt;li style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Variables may not contain any special characters, except the underscore (_), e.g.&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;top_score&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Initializing Variables&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
In the above example sketches, the variables that were used were first defined, and then assigned a value.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
A variable can also be assigned an initial value when it is defined as shown below:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;int&lt;/span&gt; total = 0;
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
In this example, the integer value named&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;total&lt;/strong&gt;&amp;nbsp;is defined and assigned a value of zero (0) in one statement.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Notes&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
In this part of the course and other parts where concepts need to be explained, the example code will often be put in the&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup()&lt;/strong&gt;&amp;nbsp;part of the sketch, rather than the&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop()&lt;/strong&gt;&amp;nbsp;part. This is because the code usually only needs to run once to demonstrate some concept.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; font-weight: normal; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;&quot;&gt;
Most sketches that are written will have the bulk of the code in the&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop()&lt;/strong&gt;&amp;nbsp;function and only code that initializes hardware in the&amp;nbsp;&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup()&lt;/strong&gt;&amp;nbsp;function.&lt;/div&gt;
&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://moroccoele.blogspot.com/feeds/9144414207910441523/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2535795214191795882/9144414207910441523' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/9144414207910441523'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/9144414207910441523'/><link rel='alternate' type='text/html' href='http://moroccoele.blogspot.com/2017/02/variables.html' title='Variables'/><author><name>zouhair</name><uri>http://www.blogger.com/profile/03215618839043737171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/ra1432sFxQc/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2535795214191795882.post-6126672799626289877</id><published>2017-02-10T07:02:00.002-08:00</published><updated>2017-02-10T07:02:48.253-08:00</updated><title type='text'>Arduino Sketch Main Loop and Calling Functions</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Part 2 of the Arduino Programming Course&lt;/strong&gt;&lt;/div&gt;
&lt;div class=&quot;google_top_ad&quot; style=&quot;background: rgb(255, 255, 255); border: 0px; float: left; font-family: arial, helvetica, verdana, sans-serif; font-size: 16px; margin: 0px 10px 10px 0px; outline: 0px; padding: 0px 10px 0px 0px; vertical-align: baseline; width: 352.844px;&quot;&gt;
&lt;div class=&quot;clr_flt&quot; style=&quot;background: transparent; border: 0px; clear: both; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Part 2 of the Arduino programming course explains what a loop is in software and demonstrates how the main loop of an Arduino sketch works.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
A function in a sketch performs some task (i.e. performs a function). We say that we &quot;call a function&quot; when we use a function to perform its specified task. This is explained in the second half of this part of the course.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
The Main Loop&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
As seen in&amp;nbsp;&lt;a href=&quot;https://startingelectronics.org/software/arduino/learn-to-program-course/01-program-structure-flow&quot; style=&quot;background: transparent; border-bottom-color: rgb(19, 78, 139); border-bottom-style: dotted; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #134e8b; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;&quot;&gt;the previous part of this course&lt;/a&gt;, an Arduino sketch consists of two main functions called&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup()&lt;/b&gt;&amp;nbsp;and&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop()&lt;/b&gt;. The loop() function is the main loop in the Arduino sketch. After statements that only need to be run once have finished being executed in the setup() function, program execution starts in the loop() function.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Once program execution has started in the main loop, the statements in the main loop will be executed continuously until the Arduino is switched off or reset. The main loop is where the actual operational functionality of the Arduino takes place – for example, if the Arduino is programmed to be a flashing light sequencer, then the flashing light functionality will be placed in the main loop.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Why is it Called a Loop?&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Statements in the loop() function will be executed from top to bottom, until the bottom of the loop() function is reached. When the bottom of the loop function is reached, statements are executed from the top of the loop() function again, thus completing the &quot;loop&quot; as shown in the image below.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEja6VeKI-NCo3rZrZ47UyYy2eXeKvb4m9i_Y58DQ7X1qj4xrjEBEdAHs6yRDHe1po7FkW5LO1qkyJbdltYzhoZtU9rpHVpbV_naOa6q3ifk7-sOGjlPhAlIdAeJ9JL5FyCHsBCn3ON7XC2B/s1600/6.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEja6VeKI-NCo3rZrZ47UyYy2eXeKvb4m9i_Y58DQ7X1qj4xrjEBEdAHs6yRDHe1po7FkW5LO1qkyJbdltYzhoZtU9rpHVpbV_naOa6q3ifk7-sOGjlPhAlIdAeJ9JL5FyCHsBCn3ON7XC2B/s1600/6.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Loop Demonstration Sketch&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;main_loop&lt;/b&gt;&amp;nbsp;sketch shown below, demonstrates how the main loop works in an Arduino sketch. Type the sketch into your Arduino IDE, or copy and paste it into the IDE.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Load the sketch to the Arduino and then open the serial monitor window to see the sketch output text as it runs.&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;begin&lt;/span&gt;(9600);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;*** This message will only be displayed on start or reset. ***&quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay&lt;/span&gt;(2000);
}

&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;-- Arduino now at top of main loop. --&quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;--------------------------------------&quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay&lt;/span&gt;(2000);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Executing instructions in main loop.&quot;&lt;/span&gt;);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay&lt;/span&gt;(2000);
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Arduino now at bottom of main loop.\r\n&quot;&lt;/span&gt;);
}
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The text that the sketch prints to the serial monitor window is shown below.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIuhR3afCUulWQRcg3aFrQbKqAmcMqoMlv5CYsNndnr529aH8Nc6XJdD0ubFAwCwGiuvyWO9Xg0Ww7EVx14PkFbi50CH_LkoVj_veoOGmckXIkvJpDJgYaMp3k4qYTjjA3FuEtAdh5HQZo/s1600/7.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;195&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIuhR3afCUulWQRcg3aFrQbKqAmcMqoMlv5CYsNndnr529aH8Nc6XJdD0ubFAwCwGiuvyWO9Xg0Ww7EVx14PkFbi50CH_LkoVj_veoOGmckXIkvJpDJgYaMp3k4qYTjjA3FuEtAdh5HQZo/s320/7.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-size: 15.568px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-size: 15.568px;&quot;&gt;This video shows the above sketch running.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe width=&quot;320&quot; height=&quot;266&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/iXe3j_MuPfQ/0.jpg&quot; src=&quot;https://www.youtube.com/embed/iXe3j_MuPfQ?feature=player_embedded&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
As the above demonstration shows, the text in the setup() function is only displayed once when the serial monitor window is first opened and the Arduino is reset. After this, program execution enters the loop() function and repeatedly executes the statements in the loop from top to bottom and back to the top again in a never ending loop.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
Functions in the Loop Demonstration Sketch&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
In the main_loop sketch above, each statement in setup() and loop() consists of a function being called – i.e. being called means that it is executed or run.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The delay() Function&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
When the&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay()&lt;/b&gt;&amp;nbsp;function is called in the statement&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay(2000);&lt;/b&gt;&amp;nbsp;then the delay function causes a waiting period of 2 seconds (2000 milliseconds – there are 1000 milliseconds in one second, also written 1000ms). The time of the delay can be changed by passing a different value to delay(), e.g. 3000 will cause a 3 second delay:&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay(3000);&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The println() Function&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println()&lt;/b&gt;&amp;nbsp;function sends text out of the serial / USB port of the Arduino and is displayed in the serial monitor window.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The println() function is different from the delay() function in that it has&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/b&gt;&amp;nbsp;and a dot (.) before it:&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial.println(&quot;Text to print.&quot;);&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The reason for this notation (Serial.&lt;i style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;function_name()&lt;/i&gt;) is because the function acts on the serial port or Serial object. You will notice in setup() that&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial.begin()&lt;/b&gt;&amp;nbsp;is called. This is the begin() function acting on the serial port – in this case to set it to the desired speed.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
These functions that are preceded by an object name (e.g. Serial) are called &quot;methods&quot; in object oriented programming.&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
A Summary of Functions&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The following will hopefully clear up what functions are and the terminology used with them. A deeper understanding of functions will only be possible once we start writing our own functions.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
setup() and loop()&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;setup()&lt;/b&gt;&amp;nbsp;and&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop()&lt;/b&gt;&amp;nbsp;are two special functions that form part of the structure of an Arduino sketch.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
We are actually writing these special functions by giving them a function body (between the opening and closing braces:&amp;nbsp;&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;{}&lt;/b&gt;) and writing statements in the function body.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The statements in these functions in the above sketch were calling pre-existing functions that perform the tasks that we want, e.g. set up the serial port speed, cause a time delay, write text to the serial monitor window.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The setup() and loop() functions are automatically called at the right time because they are special Arduino functions.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Calling Functions&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
By calling or using pre-existing functions, we are using code that someone else has already written.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The delay() function has a function body that contains statements that cause it to perform a delay. We do not see these statements or the function body because they are either part of the Arduino programming language or exist in an external function library.&lt;/div&gt;
&lt;h3 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.15em; margin: 30px 0px 5px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Passing a Value to a Function&lt;/h3&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
When a value (e.g. a number or text string) is used by a function, we must pass the value to the function.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Passing a Value to the delay() Function&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
We call the delay() function in the sketch as in the following statement:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay&lt;/span&gt;(2000);
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The delay value in milliseconds (2000) is said to be passed to the function.&lt;/div&gt;
&lt;h4 style=&quot;background: rgb(255, 255, 255); border: 0px; color: #3b3b3b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 16px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Passing a Value to the println() Function&lt;/h4&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
We pass a text string to the println() function as shown in this statement:&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 670.406px;&quot;&gt;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Executing instructions in main loop.&quot;&lt;/span&gt;);
&lt;/pre&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
We must pass the text string to the function so that the function knows what to send out of the serial / USB port. The text between the opening and closing quotation marks (&lt;b style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;&quot;&lt;/b&gt;) is known as a&amp;nbsp;&lt;em style=&quot;background: transparent; border: 0px; font-size: 15.568px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;string&lt;/em&gt;&amp;nbsp;in programming.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;br style=&quot;color: black; font-size: 16px;&quot; /&gt;&lt;br style=&quot;color: black; font-size: 16px;&quot; /&gt;&lt;br style=&quot;color: black; font-size: 16px;&quot; /&gt;&lt;/div&gt;
&lt;h2 style=&quot;background: rgb(255, 255, 255); border-bottom-color: rgb(221, 221, 255); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: #30465b; font-family: times, &amp;quot;times new roman&amp;quot;, georgia, serif; font-size: 1.3em; margin: 40px 0px 5px; outline: 0px; overflow: hidden; padding: 0px; vertical-align: baseline;&quot;&gt;
A Commentary on the main_loop Sketch&lt;/h2&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The main_loop sketch from above can be seen here again, but with commentary explaining what is happening in the sketch.&lt;/div&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: 0px; color: #444444; font-family: arial, helvetica, verdana, sans-serif; font-size: 0.973em; margin-bottom: 10px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 653.406px;&quot;&gt;
A 2 second delay has been added so that the next text to be displayed in the serial
monitor window does not appear immediately.
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay&lt;/span&gt;(2000);
}

The statements in the setup() functions have all finished being executed, so now the
loop() function is called automatically.
&lt;span style=&quot;background: transparent; border: 0px; color: #00979c; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;void&lt;/span&gt; &lt;span style=&quot;background: transparent; border: 0px; color: #5e6d03; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;loop&lt;/span&gt;() {
Now that execution is taking place in the loop, the statements inside the loop()
function will be executed from top to bottom. When the bottom of the loop is reached,
all the statements will be executed again from top to bottom.
 
This text is sent to the serial monitor window and is the first statement to be
executed in the loop.
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;-- Arduino now at top of main loop. --&quot;&lt;/span&gt;);

This text is just to highlight that we are at the top of the loop. Because there is
no delay between the above text and this text, both appear at the same time in the
serial monitor window.
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;--------------------------------------&quot;&lt;/span&gt;);

A two second delay so that the line of text that follows does not appear instantly
with the above text.
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay&lt;/span&gt;(2000);

We are now executing statements (also called instructions) in the middle of the main
Arduino loop. This statement sends more text to the serial monitor window.
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Executing instructions in main loop.&quot;&lt;/span&gt;);

Another delay so that the line of text that follows does not appear at the same time
as the line of text above.
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;delay&lt;/span&gt;(2000);

The last statement in the loop and the last text that gets sent to the serial monitor
window before returning to the top of the loop to start executing statements again.
The println() function causes the invisible cursor to move to the next line in the
serial monitor window. This causes the next text sent to the serial monitor window
to appear on the line below the currently printed text.
The \r\n at the end of this text of string moves the invisible cursor down one more
line leaving a blank line between the text printed at the bottom of the loop and the
text printed at the top of the loop.
&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Serial&lt;/span&gt;.&lt;span style=&quot;background: transparent; border: 0px; color: #d35400; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;println&lt;/span&gt;(&lt;span style=&quot;background: transparent; border: 0px; color: #005c5f; font-size: 12.8px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&quot;Arduino now at bottom of main loop.\r\n&quot;&lt;/span&gt;);
}&lt;/pre&gt;
&lt;pre class=&quot;code&quot; style=&quot;background: rgb(238, 238, 238); border: 0px; font-family: courier, &amp;quot;courier new&amp;quot;, monospace; font-size: 0.8em; font-weight: bold; margin-bottom: 8px; margin-top: 10px; max-height: 500px; max-width: 720px; outline: 0px; overflow: auto; padding: 10px; vertical-align: baseline; width: 653.406px;&quot;&gt;
&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://moroccoele.blogspot.com/feeds/6126672799626289877/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2535795214191795882/6126672799626289877' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/6126672799626289877'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2535795214191795882/posts/default/6126672799626289877'/><link rel='alternate' type='text/html' href='http://moroccoele.blogspot.com/2017/02/arduino-sketch-main-loop-and-calling.html' title='Arduino Sketch Main Loop and Calling Functions'/><author><name>zouhair</name><uri>http://www.blogger.com/profile/03215618839043737171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEja6VeKI-NCo3rZrZ47UyYy2eXeKvb4m9i_Y58DQ7X1qj4xrjEBEdAHs6yRDHe1po7FkW5LO1qkyJbdltYzhoZtU9rpHVpbV_naOa6q3ifk7-sOGjlPhAlIdAeJ9JL5FyCHsBCn3ON7XC2B/s72-c/6.png" height="72" width="72"/><thr:total>0</thr:total></entry></feed>