show icon
Shows a ready-made picture. Basic › show icon; click the picture to choose another.
basic.showIcon(IconNames.Heart)
micro:bit Foundations · Find each block in the MakeCode toolbox (the category is at the end of each line).
Shows a ready-made picture. Basic › show icon; click the picture to choose another.
basic.showIcon(IconNames.Heart)
Scrolls a word or message across the screen. Basic › show string.
basic.showString("Hello")
Shows an arrow pointing a direction. Basic › more › show arrow.
basic.showArrow(ArrowNames.West)
Waits before the next block. 1000 ms is one second. Basic › pause.
basic.pause(500)
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)
})
Draw your own picture: click squares to light them (# is on). Basic › show leds.
basic.showLeds(`
. # . # .
# # # # #
# # # # #
. # # # .
. . # . .
`)
Shows a number; numbers above 9 scroll. Basic › show number.
basic.showNumber(0)
Turns every LED off. Basic › more › clear screen.
basic.clearScreen()
Runs the blocks inside again and again. Blocks in on start run only once.
basic.forever(function () {
blocks
})
Runs the blocks inside every time the button is pressed. Choose A, B or A+B. Input.
input.onButtonPressed(Button.A, function () {
blocks
})
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
})
Puts a value in a variable, throwing the old value away. Make the variable in Variables first.
let count = 0
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)
})
Lights more LEDs for a bigger value. The second number is the biggest value. Led.
led.plotBarGraph(value, 255)
Adds to a variable's value. Change by -1 counts down. Variables.
count += 1
How bright it is: 0 (dark) to 255 (bright). Input.
input.lightLevel()
How warm it is, in degrees Celsius. Input.
input.temperature()
Tilt: x is left (below 0) and right (above 0), y is forward and back. Input › more.
input.acceleration(Dimension.X)
Exactly one part runs: the first when the condition is true, else the second. Click + on an if block.
if (condition) {
blocks
} else {
blocks
}
Runs the blocks inside only when the condition is true; does nothing when it is false. Logic.
if (condition) {
blocks
}
Another question, asked only if the ones above were false. The first true one wins.
} else if (condition) {
Many values in order under one name. Places start at 0. Advanced › Arrays.
let answers = ["Yes", "No"]
How many items are in the list. The last place is the length − 1. Arrays.
answers.length
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 item at a place in the list, counted from 0. Arrays.
answers[0]
A random whole number from the first to the second, both included. Math.
randint(0, 10)
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])
})