show icon
Shows a ready-made picture. Basic › show icon; click the picture to choose another.
basic.showIcon(IconNames.Heart)
Secret messages · 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)
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 only when the condition is true; does nothing when it is false. Logic.
if (condition) {
blocks
}
Picks a channel (0 to 255). Only micro:bits in the same group hear each other. Radio.
radio.setGroup(1)
Runs each time a word arrives; receivedString holds it. Radio.
radio.onReceivedString(function (receivedString) {
blocks
})
The letter at a place in a text. Places start at 0, as in a list. Text (char from … at).
message.charAt(0)
How many letters (and spaces) a text has. The last letter is at place length − 1. Text.
message.length
Scrolls a word or message across the screen. Basic › show string.
basic.showString("Hello")
Turns every LED off. Basic › more › clear screen.
basic.clearScreen()
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)
})
A function with an input. Call it with a value: showScore(5). Functions › Add a parameter.
function showScore (points: number) {
blocks
}
Sends a word to every other micro:bit in the group. Radio.
radio.sendString("hi")
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
}
Joins two texts, one after the other: "AB" + "C" is "ABC". Text (join).
result = letter + result
Shows a number; numbers above 9 scroll. Basic › show number.
basic.showNumber(0)
Adds to a variable's value. Change by -1 counts down. Variables.
count += 1
Runs each time a number arrives; receivedNumber holds it. Radio.
radio.onReceivedNumber(function (receivedNumber) {
blocks
})
The place where something first appears in a text, counted from 0, or -1 if it is not there. Text (find index of … in …).
alphabet.indexOf(letter)
XOR: compares two numbers bit by bit. Doing it again with the same key brings the number back, so one key locks and unlocks. Written ^ in JavaScript and Python.
message ^ key
Puts a value in a variable, throwing the old value away. Make the variable in Variables first.
let count = 0
Sends a number to every other micro:bit in the group. Radio.
radio.sendNumber(0)
One on radio received gets every message; receivedNumber says which one arrived.
radio.onReceivedNumber(function (receivedNumber) {
if (receivedNumber == 1) {
blocks
} else if (receivedNumber == 2) {
blocks
}
})
What is left over after dividing: 27 % 26 is 1. Wraps a count back round to the start. Math (remainder of … ÷ …).
place % 26
Waits before the next block. 1000 ms is one second. Basic › pause.
basic.pause(500)
Another question, asked only if the ones above were false. The first true one wins.
} else if (condition) {
Sends a name and a number by radio, such as bin and 1. Radio.
radio.sendValue("bin", 1)
Exactly one part runs: the first when the condition is true, else the second. Click + on an if block.
if (condition) {
blocks
} else {
blocks
}
A random whole number from the first to the second, both included. Math.
randint(0, 10)
Runs each time a name and number arrive by radio. Radio.
radio.onReceivedValue(function (name, value) {
blocks
})
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
The item at a place in the list, counted from 0. Arrays.
answers[0]
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])
})