<?xml-stylesheet type="text/xsl" href="https://community.element14.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>how to use multiple buttons with arduino???????</title><link>/products/arduino/b/blog/posts/how-to-use-multiple-buttons-with-arduino</link><description>ok so i am new to arduino. i am trying to have one button turn on the led witch is in pin 13 and another button to turn it off but im having problems. when i press the button it turns on when i let off the button it goes off. here is my code so...</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: how to use multiple buttons with arduino???????</title><link>https://community.element14.com/products/arduino/b/blog/posts/how-to-use-multiple-buttons-with-arduino</link><pubDate>Thu, 01 Dec 2016 11:15:30 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:15f94346-2e60-48e2-90e0-15700c581efb</guid><dc:creator>engineerhitesh</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;&lt;span&gt;I want to use multiple digital pins like 3,4,5 ,here is code only for 2 number pin .how can i use multiple pins having same function in this code ..which are the changes are require in this code?.please help ,thank you...&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;span&gt;int&lt;/span&gt; &lt;span&gt;state&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; &lt;span&gt;0&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;const&lt;/span&gt; &lt;span&gt;int&lt;/span&gt; &lt;span&gt;pin&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; &lt;span&gt;2&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;void&lt;/span&gt; &lt;span&gt;setup&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &lt;span&gt;//Set Exact Baud rate of the GSM/GPRS Module.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &lt;strong&gt;Serial&lt;/strong&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;begin&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;9600&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;void&lt;/span&gt; &lt;span&gt;loop&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &lt;span&gt;if&lt;/span&gt; &lt;span&gt;(&lt;/span&gt;&lt;span&gt;digitalRead&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;pin&lt;/span&gt;&lt;span&gt;)&lt;/span&gt; &lt;span&gt;==&lt;/span&gt; &lt;span&gt;HIGH&lt;/span&gt; &lt;span&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span&gt;state&lt;/span&gt; &lt;span&gt;==&lt;/span&gt; &lt;span&gt;0&lt;/span&gt;&lt;span&gt;)&lt;/span&gt; &lt;span&gt;{&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;strong&gt;Serial&lt;/strong&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;print&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;quot;\r&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span&gt;delay&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;1000&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;strong&gt;Serial&lt;/strong&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;print&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;quot;AT+CMGF=1\r&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span&gt;delay&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;1000&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span&gt;/*Replace XXXXXXXXXX to 10 digit mobile number &amp;amp;&lt;/span&gt;&lt;/p&gt;&lt;pre style="font-style:normal;font-weight:normal;text-align:left;text-indent:0px;"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ZZ to 2 digit country code*/&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;strong&gt;Serial&lt;/strong&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;print&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;quot;AT+CMGS=\&amp;quot;+ZZXXXXXXXXXX\&amp;quot;\r&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span&gt;delay&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;1000&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span&gt;//The text of the message to be sent.&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;strong&gt;Serial&lt;/strong&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;print&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;quot;HELLO WORLD&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span&gt;delay&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;1000&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;strong&gt;Serial&lt;/strong&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;write&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;0x1A&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span&gt;delay&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;1000&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span&gt;state&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; &lt;span&gt;1&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &lt;span&gt;}&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &lt;span&gt;else&lt;/span&gt; &lt;span&gt;{&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span&gt;state&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; &lt;span&gt;0&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &lt;span&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;img src="https://community.element14.com/aggbug?PostID=20053&amp;AppID=145&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: how to use multiple buttons with arduino???????</title><link>https://community.element14.com/products/arduino/b/blog/posts/how-to-use-multiple-buttons-with-arduino</link><pubDate>Wed, 08 Apr 2015 16:31:30 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:15f94346-2e60-48e2-90e0-15700c581efb</guid><dc:creator>e14 Contributor</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Dear N&lt;span class="jive-blog-post-subject-stats"&gt;&lt;a class="jive-link-external-small" href="http://www.element14.com/community/people/nmmbeginer" target="_blank"&gt;athanael&lt;/a&gt;&lt;/span&gt; (and others reading this)...&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;By all means... press on in the direction you have started, get it &amp;quot;working&amp;quot;... but learn this from this project: One of the great things about &amp;quot;playing&amp;quot; with Arduinos is that there is no one right answer!&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;There are all sorts of ways to do JUST &amp;quot;turn lights on and off with buttons&amp;quot;.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;The idea you had originally, one button for on, one for off, is something that would actually be used in some real world applications. Once you get the other answer working, go back, try to get your original idea working TOO! (^_^)&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Before long, you&amp;#39;re going to need to learn about, conquer &amp;quot;switch de-bouncing&amp;quot;. Google will give you a lifetime of discussions of the matter.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Think about this challenge. It may SEEM &amp;quot;simple&amp;quot; enough at first... but it is harder than it seems. And harder to program WELL. (Code that WORKS is not necessarily GOOD code)&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Set up an Arduino with 3 (or more) buttons, 3 or more LEDs. Each button triggers a different &amp;quot;pretty pattern&amp;quot; on the LEDs... for the real challenge to emerge, these patterns have to be &amp;quot;long&amp;quot;... say, five seconds to repeat themselves. So... pattern 1 might be &amp;quot;first LED on, wait two seconds, second LED on, wait two seconds, third LED on, wait two seconds. Turn all off and immediately start again.&amp;quot;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;The tricky bit, unless you are lucky (or brilliant) with how you went about it: Fixing things so that if you press button 2 when the LEDs are half way through doing pattern 1, the Arduino switches (immediately) do doing pattern two.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Now... if you have lots of LEDs... 6?... and only two buttons, you could still demand three patterns. One for button 1 pressed. One for button 2 pressed. A different one for BOTH buttons pressed. (If neither button is pressed, it should carry on doing whatever it was doing before.)&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;THAT is not easy. Be sure to write it in a way that makes it trivial to add a third button if you think you can come up with 7 interesting patterns. If you use a few smart LEDs, you can certainly make 7 fun patterns.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Smart LEDs?....&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;www.arunet.co.uk/tkboyd/ec/WS2812&lt;strong&gt;SmartLED&lt;/strong&gt;s.htm&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=20053&amp;AppID=145&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: how to use multiple buttons with arduino???????</title><link>https://community.element14.com/products/arduino/b/blog/posts/how-to-use-multiple-buttons-with-arduino</link><pubDate>Sun, 01 Mar 2015 22:43:41 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:15f94346-2e60-48e2-90e0-15700c581efb</guid><dc:creator>clem57</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;First you really need only 1 button! Add a variable that remembers whether LED is on/off. When buttonState is HIGH then change LED state by flipping the bit with XOR:&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;int LEDState&amp;nbsp; = 0; // Put this up top&lt;/p&gt;&lt;p&gt;// flip it&lt;/p&gt;&lt;p&gt;LEDState ^= 1;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Change LED with&lt;/p&gt;&lt;p&gt;&lt;span&gt;digitalWrite(ledPin, LEDState);&amp;nbsp; // 0 for off and 1 for on!&lt;/span&gt;&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=20053&amp;AppID=145&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item></channel></rss>