Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.097 X-Spam-Evidence: '*H*': 0.81; '*S*': 0.00; 'benjamin': 0.09; 'expected,': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'true:': 0.16; 'wrote:': 0.16; '(in': 0.18; 'header :In-Reply-To:1': 0.24; 'second': 0.24; 'testing': 0.25; 'header :User-Agent:1': 0.26; 'command': 0.28; 'actual': 0.29; 'prints': 0.29; 'guess': 0.29; 'push': 0.31; 'code': 0.31; 'run': 0.32; 'probably': 0.32; 'curious': 0.33; 'add': 0.34; 'message- id:@gmail.com': 0.35; 'to:addr:python-list': 0.35; "isn't": 0.35; 'there': 0.36; 'subject:: ': 0.37; 'skip:g 20': 0.37; 'received:org': 0.38; 'button': 0.38; 'pm,': 0.39; 'expect': 0.39; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'some': 0.40; 'your': 0.60; 'times': 0.61; 'here': 0.66; 'case?': 0.84; 'oscar': 0.84; 'bounce': 0.91 X-Virus-Scanned: amavisd-new at torriefamily.org Date: Thu, 18 Jun 2015 16:42:14 -0600 From: Michael Torrie User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Keypress Input References: <5580CBC6.3000402@gmail.com> In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1434667341 news.xs4all.nl 2843 [2001:888:2000:d::a6]:39545 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:92858 On 06/18/2015 01:35 PM, Oscar Benjamin wrote: > I use the following. I found in testing that when you push the button it > prints 'Button pressed' 10 times a second (in actual use it calls poweroff > so I guess bounce isn't an issue there). Is there some reason it needs to > be cleverer in this case? Yes, that would be expected, given your code has a while loop that never exits. Just curious what you expect the code to do that it's not doing. You are probably right that debouncing isn't important in your application. So just add your poweroff command after the print() statement, and break out of the loop: ... while True: time.sleep(0.1) if not GPIO.input(PIN_NUM): print('Button pressed') # run shutdown command here os.system('/usr/sbin/shutdown') break