← Reference

Messages in the air: cheat sheet

Secret messages · Find each block in the MakeCode toolbox (the category is at the end of each line).

show icon

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

basic.showIcon(IconNames.Heart)
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

if

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

if (condition) {
    blocks
}
The block

radio set group

Picks a channel (0 to 255). Only micro:bits in the same group hear each other. Radio.

radio.setGroup(1)
The block

on radio received string

Runs each time a word arrives; receivedString holds it. Radio.

radio.onReceivedString(function (receivedString) {
    blocks
})
The block

letter at

The letter at a place in a text. Places start at 0, as in a list. Text (char from … at).

message.charAt(0)
The block

length of text

How many letters (and spaces) a text has. The last letter is at place length − 1. Text.

message.length
The block

show string

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

basic.showString("Hello")
The block

clear screen

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

basic.clearScreen()
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

function with a parameter

A function with an input. Call it with a value: showScore(5). Functions › Add a parameter.

function showScore (points: number) {
    blocks
}
The block

radio send string

Sends a word to every other micro:bit in the group. Radio.

radio.sendString("hi")
The block

for index

Runs the blocks inside once for each number from 0 up to the last one, with index set to that number each time. Loops.

for (let index = 0; index <= 4; index++) {
    blocks
}
The block

join

Joins two texts, one after the other: "AB" + "C" is "ABC". Text (join).

result = letter + result
The block