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)".

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to