Micro Bit push button and display image example

A simple example using the 2 buttons (a and b), pressing them will display one of the built in images on th 5×5 LED display on the Micro Bit

The Image Class can display a wide variety of images, you can change these in the code below

  • Image.HEART
  • Image.HEART_SMALL
  • Image.HAPPY
  • Image.SMILE
  • Image.SAD
  • Image.CONFUSED
  • Image.ANGRY
  • Image.ASLEEP
  • Image.SURPRISED
  • Image.SILLY
  • Image.FABULOUS
  • Image.MEH
  • Image.YES
  • Image.NO
  • Image.CLOCK12, Image.CLOCK11, Image.CLOCK10, Image.CLOCK9, Image.CLOCK8, Image.CLOCK7, Image.CLOCK6, Image.CLOCK5, Image.CLOCK4, Image.CLOCK3, Image.CLOCK2, Image.CLOCK1
  • Image.ARROW_N, Image.ARROW_NE, Image.ARROW_E, Image.ARROW_SE, Image.ARROW_S, Image.ARROW_SW, Image.ARROW_W, Image.ARROW_NW
  • Image.TRIANGLE
  • Image.TRIANGLE_LEFT
  • Image.CHESSBOARD
  • Image.DIAMOND
  • Image.DIAMOND_SMALL
  • Image.SQUARE
  • Image.SQUARE_SMALL
  • Image.RABBIT
  • Image.COW
  • Image.MUSIC_CROTCHET
  • Image.MUSIC_QUAVER
  • Image.MUSIC_QUAVERS
  • Image.PITCHFORK
  • Image.XMAS
  • Image.PACMAN
  • Image.TARGET
  • Image.TSHIRT
  • Image.ROLLERSKATE
  • Image.DUCK
  • Image.HOUSE
  • Image.TORTOISE
  • Image.BUTTERFLY
  • Image.STICKFIGURE
  • Image.GHOST
  • Image.SWORD
  • Image.GIRAFFE
  • Image.SKULL
  • Image.UMBRELLA
  • Image.SNAKE

 

http://microbit-micropython.readthedocs.io/en/latest/image.html – has more information on the
Code

This was written using the http://codewith.mu/ python editor

[codesyntax lang=”python”]

from microbit import *

# Write your code here :-)
while True:
    if button_a.is_pressed() and button_b.is_pressed():
        display.show(Image.CONFUSED)
    elif button_a.is_pressed():
        display.show(Image.YES)
    elif button_b.is_pressed():
        display.show(Image.NO)
    sleep(100)

[/codesyntax]

Related posts

Microbit tune selector example

Microbit and an AD keypad

Microbit and Neopixel examples