Cheat sheet for the BBC Micro:Bit
from microbit import *
You always need to have the
from microbit import * line at the start of your program
If you use random, music or radio in your program you need to remember to also import them at the top of your program as well
temp = temperature()
time = running_time()
sleep tells the Microbit to stop doing anything for as long as you tell it
temperature gets the current temperature
running_time gets the amount of time since the Microbit started running the program
Show a happy face if button A is being pressed or show a sad face is button B is being pressed.
randrange picks a random number in the range
random.choice picks a random thing out of a list of things
display.set_pixel(0, 0, 9)
message = radio.receive()
When you have more than 1 Microbit, you can send and receive messages using the radio.
If there are other Microbits using the radio around you, make sure that you are using a different channel number (using
radio.config) so that you aren't accidentally receiving their messages
gesture == "up"
gesture == "down"
gesture == "left"
gesture == "right"
gesture == "face up"
gesture == "face down"
gesture == "shake"
music.play(music.BIRTHDAY, wait=False, loop=True)
tune = ['C4:4', 'D4:4', 'A4:4']
Setting wait=False tells the Microbit to play the music and keep going with the rest of the program, otherwise it will wait until the music is done
Setting loop=True, will keep looping the music over and over instead of just playing once
gesture = accelerometer.current_gesture()
if gesture == "shake":
This code checks what the current gesture is that is happening to the Microbit and shows a sad face if it is a shake