Button A and Button B
button_a.is_pressed():
button_b.is_pressed():
BUTTON A AND B EXAMPLE
from microbit import *
while True:
if button_a.is_pressed():
display.show(Image.HAPPY)
elif button_b.is_pressed():
break
else:
display.show(Image.SAD)
display.clear()
BUTTON EXAMPLE 2
# Press button A for a fortune cookie.
from microbit import *
import random
fortunes = [
"Never step off a moving bus",
"This sentence is false",
"The meaning of life is overrated",
"Do not touch!",
"You will receive some advice",
"My hovercraft is full of eels",
]
while True:
if button_a.is_pressed():
cookie = random.choice(fortunes)
display.scroll(cookie)
fortunes is set up to be an array of 6 text elements
pressing the A button uses the random class to select one text element from the array into a variable called "cookie", cookie is then sent to the LED display