<?xml version="1.0" encoding="UTF-8" ?>
<?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/"><channel><title>need help with pull up on input</title><link>https://community.element14.com/technologies/code_exchange/w/documents/1945/need-help-with-pull-up-on-input</link><description /><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>need help with pull up on input</title><link>https://community.element14.com/technologies/code_exchange/w/documents/1945/need-help-with-pull-up-on-input</link><pubDate>Wed, 06 Oct 2021 21:02:14 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:e3035cf5-1c9d-4cb3-8480-10dbe3721f8f</guid><dc:creator>joetrotter</dc:creator><comments>https://community.element14.com/technologies/code_exchange/w/documents/1945/need-help-with-pull-up-on-input#comments</comments><description>Current Revision posted to Documents by joetrotter on 10/6/2021 9:02:14 PM&lt;br /&gt;
&lt;p style="margin:0;"&gt;I am using the gertboard and wiringPi ,and trying to figure out the buttons. The program reads the low when the pull is pushed, but when not pushed, the input is acting as if it is floating and reading random HIGH and LOW. Im a teacher, new to RaspberryPi, beginner&amp;nbsp; programmer, and am trying to further my knowledge of C. Any help is appreciated. My code is:&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;#include &amp;lt;wiringPi.h&amp;gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;#include &amp;lt;math.h&amp;gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;#include &amp;lt;time.h&amp;gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;int main(void)&lt;/p&gt;&lt;p style="margin:0;"&gt;{&lt;/p&gt;&lt;p style="margin:0;"&gt;wiringPiSetupGpio();&lt;/p&gt;&lt;p style="margin:0;"&gt;pinMode(25,INPUT);&lt;/p&gt;&lt;p style="margin:0;"&gt;pullUpDnControl(25,PUD_UP); &lt;/p&gt;&lt;p style="margin:0;"&gt;pinMode(17,OUTPUT);&lt;/p&gt;&lt;p style="margin:0;"&gt;pinMode(24,OUTPUT);&amp;nbsp; //if these unused i/o left not set up. they follow GPIO 17 for some reason&lt;/p&gt;&lt;p style="margin:0;"&gt;digitalWrite(24,LOW);&lt;/p&gt;&lt;p style="margin:0;"&gt;pinMode(23,OUTPUT);&lt;/p&gt;&lt;p style="margin:0;"&gt;digitalWrite(23,LOW);&lt;/p&gt;&lt;p style="margin:0;"&gt;pinMode(22,OUTPUT);&lt;/p&gt;&lt;p style="margin:0;"&gt;digitalWrite(22,LOW);&lt;/p&gt;&lt;p style="margin:0;"&gt;pinMode(21,OUTPUT);&lt;/p&gt;&lt;p style="margin:0;"&gt;digitalWrite(21,LOW);&lt;/p&gt;&lt;p style="margin:0;"&gt;pinMode(18,OUTPUT);&lt;/p&gt;&lt;p style="margin:0;"&gt;digitalWrite(18,LOW);&lt;/p&gt;&lt;p style="margin:0;"&gt;pinMode(15,OUTPUT);&lt;/p&gt;&lt;p style="margin:0;"&gt;digitalWrite(15,LOW);&lt;/p&gt;&lt;p style="margin:0;"&gt;int x=0;&lt;/p&gt;&lt;p style="margin:0;"&gt;while(x&amp;lt;20)&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre;"&gt; &lt;/span&gt;{&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre;"&gt; &lt;/span&gt;if (digitalRead(25)==LOW)&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre;"&gt; &lt;/span&gt;{&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre;"&gt; &lt;/span&gt;printf(&amp;quot;pushed LED ON, %i\n&amp;quot;,x);&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre;"&gt; &lt;/span&gt;digitalWrite(17,HIGH);&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre;"&gt; &lt;/span&gt;while (digitalRead(25)==LOW)&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre;"&gt; &lt;/span&gt;{;}&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre;"&gt; &lt;/span&gt;}&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre;"&gt; &lt;/span&gt;if (digitalRead(25)==HIGH)&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre;"&gt; &lt;/span&gt;{&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre;"&gt; &lt;/span&gt;printf(&amp;quot;not pushed LED OFF , %i\n&amp;quot;,x);&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre;"&gt; &lt;/span&gt;digitalWrite(17,LOW);&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre;"&gt; &lt;/span&gt;while (digitalRead(25)==HIGH)&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre;"&gt; &lt;/span&gt;{;}&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre;"&gt; &lt;/span&gt;x++;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre;"&gt; &lt;/span&gt;}&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre;"&gt; &lt;/span&gt;}&lt;/p&gt;&lt;p style="margin:0;"&gt;return 0;&lt;/p&gt;&lt;p style="margin:0;"&gt;}&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre;"&gt; &lt;/span&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;
</description></item></channel></rss>