Buttons¶
There are two buttons on the board, called button_a
and button_b
.
Attributes¶
A
Button
instance (see below) representing the left button.
Represents the right button.
Classes¶
-
class
Button
¶ Represents a button.
注解
This class is not actually available to the user, it is only used by the two button instances, which are provided already initialized.
-
is_pressed
()¶ Returns
True
if the specified buttonbutton
is pressed, andFalse
otherwise.
-
was_pressed
()¶ Returns
True
orFalse
to indicate if the button was pressed since the device started or the last time this method was called.
-
get_presses
()¶ Returns the running total of button presses, and resets this total to zero before returning.
-
Example¶
import microbit
while True:
if microbit.button_a.is_pressed() and microbit.button_b.is_pressed():
microbit.display.scroll("AB")
break
elif microbit.button_a.is_pressed():
microbit.display.scroll("A")
elif microbit.button_b.is_pressed():
microbit.display.scroll("B")
microbit.sleep(100)