Code Sample Descriptions
1
Hello World in MakeCode (JavaScript view)
basic.showString("Hello World")
A simple MakeCode project that shows 'Hello World' on the micro:bit LED display. Blocks generate the JavaScript code below.
2
Scroll Text on micro:bit
basic.showString("Welcome!")
Scrolls a custom message on the micro:bit LED display.
3
Display a Heart Icon
basic.showIcon(IconNames.Heart)
Shows a heart icon on the micro:bit LED display.
4
Blink an LED
basic.forever(function () {
led.toggle(2, 2)
basic.pause(500)
})
Turns the built-in LED on and off repeatedly.
5
Button A Pressed Message
input.onButtonPressed(Button.A, function () {
basic.showString("Button A!")
})
Displays a message when Button A is pressed.
6
Count from 1 to 5
for (let i = 1; i <= 5; i++) {
basic.showNumber(i)
basic.pause(500)
}
Counts numbers from 1 to 5 on the LED display.
7
Display Random Number
basic.showNumber(Math.randomRange(1, 10))
Shows a random number between 1 and 10 on the LED display.
8
Tilt Detection
basic.forever(function () {
if (input.isGesture(Gesture.TiltLeft)) {
basic.showString("Left")
} else if (input.isGesture(Gesture.TiltRight)) {
basic.showString("Right")
}
})
Displays a message when the micro:bit is tilted left or right.
9
Show Multiple Icons
basic.showIcon(IconNames.Happy)
basic.pause(500)
basic.showIcon(IconNames.Sad)
basic.pause(500)
basic.showIcon(IconNames.Heart)
Displays a sequence of icons on the LED display.
10
Temperature Display
basic.showNumber(input.temperature())
Displays the current temperature measured by the micro:bit.