{"id":3886,"date":"2021-10-21T20:23:42","date_gmt":"2021-10-21T20:23:42","guid":{"rendered":"http:\/\/rodmilstead.com\/pt\/?page_id=3886"},"modified":"2022-10-10T17:57:16","modified_gmt":"2022-10-10T17:57:16","slug":"arduino-adding-an-input-and-sample-code","status":"publish","type":"page","link":"http:\/\/rodmilstead.com\/pt\/arduino-adding-an-input-and-sample-code\/","title":{"rendered":"Arduino &#8211; adding an input and sample code"},"content":{"rendered":"<ol>\n<li><strong>Start in Tinkercad and build this program and circuit<\/strong><\/li>\n<li><strong>Then build your circuit with a real Arduino and breadboard.<\/strong><br \/>\nUse the diagram below to add a button to your circuit. \u00a0Pay close attention to the types of resistors (look at the colored stripes).<\/li>\n<li>When you are done, t<strong>urn in two items on Canvas:<\/strong><br \/>\n1. turn in the link to your Tinkercad program with four LEDS, a button and serial monitor <a href=\"http:\/\/rodmilstead.com\/pt\/subtcad\/\" target=\"_blank\" rel=\"noopener\">by following these instructions.<\/a><br \/>\n2. record a short video of your REAL LIFE circuit working.<\/li>\n<\/ol>\n<p><strong>What you need:<\/strong><br \/>\none 220 resistor for each LED<br \/>\none 220 resistor for the button AND one 10k resistor for the button<br \/>\na button<br \/>\nsample code to get you started &#8211; at the bottom of this assignment<\/p>\n<p><strong>Color code:<\/strong><br \/>\nred wires- leading from pins to breadboard<br \/>\nblack wires- ground<br \/>\ngreen wires- button<br \/>\nyellow wires &#8211; input from pin 2<\/p>\n<p><strong>After you have built your sample program<\/strong> with ONE LED DO THIS:<br \/>\n-add to your program and circuit so that there are four LEDs that are triggered when the button is pressed.<br \/>\n-add <a href=\"https:\/\/rodmilstead.com\/pt\/basic-serial-monitor\/\" target=\"_blank\" rel=\"noopener\">serial monitor commands to your program<\/a> so that is shows WHEN the button is pressed.<\/p>\n<figure id=\"attachment_3479\" aria-describedby=\"caption-attachment-3479\" style=\"width: 960px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/rodmilstead.com\/pt\/wp-content\/uploads\/2020\/02\/2020-Arduino-sample-input-circuit.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-3479 size-full\" src=\"http:\/\/rodmilstead.com\/pt\/wp-content\/uploads\/2020\/02\/2020-Arduino-sample-input-circuit.png\" alt=\"\" width=\"960\" height=\"720\" srcset=\"http:\/\/rodmilstead.com\/pt\/wp-content\/uploads\/2020\/02\/2020-Arduino-sample-input-circuit.png 960w, http:\/\/rodmilstead.com\/pt\/wp-content\/uploads\/2020\/02\/2020-Arduino-sample-input-circuit-300x225.png 300w, http:\/\/rodmilstead.com\/pt\/wp-content\/uploads\/2020\/02\/2020-Arduino-sample-input-circuit-768x576.png 768w\" sizes=\"auto, (max-width: 960px) 100vw, 960px\" \/><\/a><figcaption id=\"caption-attachment-3479\" class=\"wp-caption-text\">click the image to zoom in!<\/figcaption><\/figure>\n<p><strong>Now here&#8217;s the sample code &#8211; copy and paste what&#8217;s below this into a brand new Arduino file:<\/strong><\/p>\n<p>int red = 13;<br \/>\nint button = 2;<\/p>\n<p>void setup()<br \/>\n{<br \/>\npinMode(red, OUTPUT);<\/p>\n<p>pinMode(button, INPUT);<br \/>\nSerial.begin(9600);<br \/>\n}<\/p>\n<p>void loop()<br \/>\n{<br \/>\nif(digitalRead(button) == HIGH)<br \/>\n{<br \/>\nSerial.println(&#8220;button pressed&#8221;);<br \/>\ndigitalWrite (red, HIGH);<br \/>\ndelay (500);<br \/>\ndigitalWrite(red,LOW);<br \/>\ndelay (500);<br \/>\ndigitalWrite (red, HIGH);<br \/>\ndelay (500);<br \/>\ndigitalWrite(red,LOW);<br \/>\ndelay (500);<\/p>\n<p>}<br \/>\nelse<br \/>\n{<br \/>\ndigitalWrite(red, HIGH);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Start in Tinkercad and build this program and circuit Then build your circuit with a real Arduino and breadboard. Use the diagram below to add a button to your circuit. \u00a0Pay close attention to the types of resistors (look at the colored stripes). When you are done, turn in two items on Canvas: 1. turn &hellip; <a href=\"http:\/\/rodmilstead.com\/pt\/arduino-adding-an-input-and-sample-code\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Arduino &#8211; adding an input and sample code<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-3886","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/rodmilstead.com\/pt\/wp-json\/wp\/v2\/pages\/3886","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/rodmilstead.com\/pt\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/rodmilstead.com\/pt\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/rodmilstead.com\/pt\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/rodmilstead.com\/pt\/wp-json\/wp\/v2\/comments?post=3886"}],"version-history":[{"count":8,"href":"http:\/\/rodmilstead.com\/pt\/wp-json\/wp\/v2\/pages\/3886\/revisions"}],"predecessor-version":[{"id":4502,"href":"http:\/\/rodmilstead.com\/pt\/wp-json\/wp\/v2\/pages\/3886\/revisions\/4502"}],"wp:attachment":[{"href":"http:\/\/rodmilstead.com\/pt\/wp-json\/wp\/v2\/media?parent=3886"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}