Show Menu
Cheatography

Micro:Bit Cheat Sheet by

Cheat sheet for the BBC Micro:Bit

Import

from microbit import *
import random
import music
import radio
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

General

sleep(­1000)
temp = temper­ature()
time = runnin­g_t­ime()
sleep tells the Microbit to stop doing anything for as long as you tell it

temper­ature gets the current temper­ature

runnin­g_time gets the amount of time since the Microbit started running the program

Buttons

if button_a.is_pressed():
    display.show(Image.HAPPY)

if button_b.is_pressed():
    display.show(Image.SAD)
Show a happy face if button A is being pressed or show a sad face is button B is being pressed.

Random

import random
randra­nge(1, 10)
random.ch­oic­e(t­hings)
randrange picks a random number in the range

random.choice picks a random thing out of a list of things
 

Display

displa­y.c­lear()
displa­y.s­how­(Im­age.DUCK)
displa­y.s­how­(cu­sto­mImage)
displa­y.s­cro­ll(­"­Hello World!­")
displa­y.s­et_­pix­el(0, 0, 9)
displa­y.s­how­(IM­AGE.sh­ift­_up(1))

Radio

import radio
radio.on()
message = radio.r­ec­eive()
radio.s­en­d("Hello World!­")
radio.c­on­fig­(ch­ann­el=20)
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.c­onfig) so that you aren't accide­ntally receiving their messages

Gestures

gesture == "­up"
gesture == "­dow­n"
gesture == "­lef­t"
gesture == "­rig­ht"
gesture == "face up"
gesture == "face down"
gesture == "­sha­ke"

Speech

import speech
speech.sa­y("Hello World")
 

Music

import music
music.p­la­y(m­usi­c.B­IRT­HDAY, wait=F­alse, loop=True)
music.s­top()
tune = ['C4:4', 'D4:4', 'A4:4']
music.p­la­y(tune)
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

Music

music.D­AD­ADADUM
music.E­NT­ERT­AINER
music.P­RELUDE
music.ODE
music.NYAN
music.R­IN­GTONE
music.FUNK
music.B­LUES
music.B­IR­THDAY
music.W­EDDING
music.F­UNERAL
music.P­UN­CHLINE
music.P­YTHON
music.B­ADDY
music.C­HASE
music.B­A_DING
music.W­AW­AWAWAA
music.J­UMP_UP
music.J­UM­P_DOWN
music.P­OW­ER_UP
music.P­OW­ER_DOWN

Accele­rometer

gesture = accelerometer.current_gesture()

if gesture == "shake":
    display.show(Image.SAD)
This code checks what the current gesture is that is happening to the Microbit and shows a sad face if it is a shake
           
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          FREQUENTLY USED DX CODES Cheat Sheet
          C Reference Cheat Sheet
          Java + OOP concept Cheat Sheet