Inside it, add a serial write line "A+B" block from the Serial category.
Do the same for Button B (write "B" to crouch).
Connect micro:bit via USB and click **Download** to flash your micro:bit.
MakeCode JavaScript Code Snippet:
input.onButtonPressed(Button.AB, function () {
serial.writeLine("A+B")
basic.showIcon(IconNames.Happy)
})
input.onButtonPressed(Button.A, function () {
serial.writeLine("A")
})
input.onButtonPressed(Button.B, function () {
serial.writeLine("B")
})
If you prefer MicroPython on micro:bit, use this code:
MicroPython Code:
from microbit import *
# Initialize USB serial at 115200 baud
uart.init(baudrate=115200)
while True:
if button_a.is_pressed() and button_b.is_pressed():
print("A+B")
display.show(Image.ARROW_N)
sleep(180)
display.clear()
elif button_a.is_pressed():
print("A")
sleep(120)
elif button_b.is_pressed():
print("B")
sleep(120)
sleep(20)
đ HOW TO HOST THIS GAME ON GITHUB PAGES FOR FREE:
Create a new repository on GitHub.com (e.g. mario-microbit-game).
Upload this index.html file to the root of your repository.
In your GitHub Repository, click on **Settings** â **Pages** (on the left menu).
Under **Build and deployment**, set Source to **Deploy from a branch**.
Select **Branch: main** (or master) and folder /(root), then click **Save**.
Wait 1-2 minutes! GitHub will give you a live HTTPS link (e.g. https://yourusername.github.io/mario-microbit-game). Web Serial API requires HTTPS or localhost, which GitHub Pages provides automatically!