← Teacher guide

micro:bit Foundations: cheat sheet

micro:bit Foundations · Find each block in the MakeCode toolbox (the category is at the end of each line).

Show and react

show icon

Shows a ready-made picture. Basic › show icon; click the picture to choose another.

basic.showIcon(IconNames.Heart)
The block

show string

Scrolls a word or message across the screen. Basic › show string.

basic.showString("Hello")
The block

show arrow

Shows an arrow pointing a direction. Basic › more › show arrow.

basic.showArrow(ArrowNames.West)
The block

pause

Waits before the next block. 1000 ms is one second. Basic › pause.

basic.pause(500)
The block

animation

Pictures inside forever repeat, in order. Each pause holds the picture before it.

basic.forever(function () {
    basic.showIcon(IconNames.Heart)
    basic.pause(500)
    basic.showIcon(IconNames.SmallHeart)
    basic.pause(500)
})
The block

show leds

Draw your own picture: click squares to light them (# is on). Basic › show leds.

basic.showLeds(`
    . # . # .
    # # # # #
    # # # # #
    . # # # .
    . . # . .
    `)
The block

show number

Shows a number; numbers above 9 scroll. Basic › show number.

basic.showNumber(0)
The block

clear screen

Turns every LED off. Basic › more › clear screen.

basic.clearScreen()
The block

forever

Runs the blocks inside again and again. Blocks in on start run only once.

basic.forever(function () {
    blocks
})
The block

on button pressed

Runs the blocks inside every time the button is pressed. Choose A, B or A+B. Input.

input.onButtonPressed(Button.A, function () {
    blocks
})
The block

on shake

Runs the blocks inside every time the micro:bit is shaken (or tilted, if you choose another gesture). Input.

input.onGesture(Gesture.Shake, function () {
    blocks
})
The block

Remember and sense

set variable

Puts a value in a variable, throwing the old value away. Make the variable in Variables first.

let count = 0
The block

counter

Set the start value once, in on start. change adds to whatever the variable holds now.

let count = 0
input.onButtonPressed(Button.A, function () {
    count += 1
    basic.showNumber(count)
})
The block

plot bar graph

Lights more LEDs for a bigger value. The second number is the biggest value. Led.

led.plotBarGraph(value, 255)
The block

change variable

Adds to a variable's value. Change by -1 counts down. Variables.

count += 1
The block

light level

How bright it is: 0 (dark) to 255 (bright). Input.

input.lightLevel()
The block

temperature

How warm it is, in degrees Celsius. Input.

input.temperature()
The block

Decide

acceleration

Tilt: x is left (below 0) and right (above 0), y is forward and back. Input › more.

input.acceleration(Dimension.X)
The block

if else

Exactly one part runs: the first when the condition is true, else the second. Click + on an if block.

if (condition) {
    blocks
} else {
    blocks
}
The block

if

Runs the blocks inside only when the condition is true; does nothing when it is false. Logic.

if (condition) {
    blocks
}
The block

else if

Another question, asked only if the ones above were false. The first true one wins.

} else if (condition) {
The block

Lists

list

Many values in order under one name. Places start at 0. Advanced › Arrays.

let answers = ["Yes", "No"]
The block

length of list

How many items are in the list. The last place is the length − 1. Arrays.

answers.length
The block

pick from list

A random place from 0 to length − 1 reaches every item, however long the list grows.

basic.showString(list[randint(0, list.length - 1)])
The block

get value at

The item at a place in the list, counted from 0. Arrays.

answers[0]
The block

pick random

A random whole number from the first to the second, both included. Math.

randint(0, 10)
The block

shared code

Send a place number; both micro:bits must hold the same list in the same order.

let words = ["Hi", "Yes", "No"]
radio.onReceivedNumber(function (receivedNumber) {
    basic.showString(words[receivedNumber])
})
The block