Microbit Buttons

"""
by Various / Public Domain
"""

from microbit import *


while True:
    if button_a.is_pressed() and button_b.is_pressed():
        display.show(Image.ANGRY)
    elif button_a.is_pressed():
        display.show(Image.HAPPY)
    elif button_b.is_pressed():
        display.show(Image.SAD)
    sleep(100)

Going Further

The micro:bit api lists other images that can be drawn on the display. The Image class predefined images which can be used with display.show():

display.show(Image.HAPPY)

There is a full list on the API. Or use the display module and display a picture.

Share On
Facebook Twitter Google Plus

Published: December 23, 2016 Updated: December 23, 2016

Microbit Buttons

Using the buttons on the front of the microbit to display a message

Jez Dean
Teacher