Closed jarvisteach closed 6 years ago
Actually, one thing that could be introduced, would be to always run:
r = self.parent.cmd("print(button_a.was_pressed() and button_b.was_pressed()")
r = eval(r)
In the Button class's was_pressed()
function.
If it resolves to True
then don't run the individual checks.
That would stop the counter being reset.
Then potentially True
could be returned, allowing the original and
to work.
But the side affect of that would be that True
would be returned when a single button is queried and both are being pressed (which doesn't happen in the micro:bit) - but as that already happens in bitio, it wouldn't change the interface...
Ignore all of this! There's an obvious typo in my original code - that's what you get for deciding to try something out late on a Friday night!
When trying to run the following:
Things kind of breakdown.
Pressing only
button_a
does nothing, pressingboth buttons
does nothing, pressingbutton_b
works.I remember reading somewhere that internally the microbit stores three different states for button presses. So pressing both buttons results in both
button_a.was_pressed()
andbutton_b.was_pressed()
resolving to False.Looking at the bitio code, it is only trying the separate button checks. So that first line above will always be False if both buttons are pressed, which in turn resets the
was_pressed
flag on button_a, causing the firstelif
to fail. The secondelif
only works, becauseand
is lazy in python, and button_b isn't checked in that first line.I'm not sure how you could resolve this and keep the syntax the same, but maybe a new command (class?) could be introduced:
microbit.both_buttons
and that could be queried using the same syntax (was_pressed()
,is_pressed()
, etc) - although grammatically that would look poor...