A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://microbit-micropython.readthedocs.io/en/latest/button.html below:

Website Navigation


Buttons — BBC micro:bit MicroPython 1.1.1 documentation

Buttons

There are two buttons on the board, called button_a and button_b.

Attributes
button_a

A Button instance (see below) representing the left button.

button_b

Represents the right button.

Classes
class Button

Represents a button.

Note

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 button button is currently being held down, and False otherwise.

was_pressed()

Returns True or False to indicate if the button was pressed (went from up to down) since the device started or the last time this method was called. Calling this method will clear the press state so that the button must be pressed again before this method will return True again.

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)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4