Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'elif': 0.04; 'bug.': 0.07; 'blue': 0.09; 'elegant,': 0.09; 'bug': 0.10; 'subject:Help': 0.10; 'variables': 0.15; '(2,': 0.16; '3",': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'newsgroups': 0.16; 'pressed': 0.16; 'pythonic': 0.16; 'received:192.168.1.4': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'scopes': 0.16; 'value;': 0.16; 'wrote:': 0.16; 'work,': 0.21; 'strip': 0.22; 'pass': 0.22; 'seems': 0.23; 'header:In-Reply-To:1': 0.24; 'header:User- Agent:1': 0.26; 'followed': 0.27; 'testing.': 0.29; 'code:': 0.29; 'fixed': 0.31; 'received:84': 0.32; 'problem': 0.33; 'shorter': 0.33; 'true.': 0.33; 'similar': 0.33; 'false': 0.35; 'something': 0.35; 'but': 0.36; 'too': 0.36; 'there': 0.36; 'to:addr:python- list': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'expect': 0.37; 'thanks': 0.37; 'seem': 0.37; 'starting': 0.37; 'doing': 0.38; 'button': 0.38; 'mean': 0.38; 'means': 0.39; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'share': 0.61; 'john': 0.61; 'more': 0.63; 'here': 0.66; 'subject.': 0.72; 'led': 0.72; 'basics.': 0.84; 'flashing': 0.84; 'leds': 0.84; 'non-zero': 0.84; 'yellow': 0.84; 'colour': 0.91; 'mistakes': 0.95 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=MbeRwMLf c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=EBOSESyhAAAA:8 a=IkcTkHD0fZMA:10 a=9rmJLL5phbp3o9HaJ04A:9 a=QEXdDO2ut3YA:10 X-AUTH: mrabarnett@:2500 Subject: Re: RPI.GPIO Help To: python-list@python.org References: From: MRAB Date: Fri, 11 Sep 2015 19:49:15 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed 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: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1441997544 news.xs4all.nl 23865 [2001:888:2000:d::a6]:55498 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:96363 On 2015-09-11 19:24, John McKenzie wrote: > > Hello. > > Thanks to the help of people here and in other newsgroups I seem to have > something working doing the basics. (Buttons work, colours light up > appropriately.) > > When I followed MRAB's instructions and read about scopes of variables > that solved my most recent problem, but it introduced a bug. I think I > fixed the bug but after all my stupid mistakes and forgetfulness that > seems too good to be true. I expect there is a better, more elegant, or > more Pythonic way to do what I did so please feel free to share on the > subject. > > I had a problem where if I pressed a button while the LEDs were already > flashing the colour of that button it would block a new colour from > starting when I pressed a new button. So if the LED strip was red and I > pressed the red button again nothing would happen when I pressed the blue > or yellow button. Similar problem for the other two buttons. > > So inside my callbacks I added this code: > > if colour == 1: > pass > elif colour == 2 or 3: > colour = 1 > > > Now it seems OK from my limited testing. > [snip] "colour == 2 or 3" means the same as "(colour == 2) or 3", where 3 is a true value (zero is a false value; any non-zero number is a true value). What you mean is "colour == 2 or colour == 3". A shorter alternative is "colour in (2, 3)".