Button A

Run the test

Shows SPEED stat and power bar, then drives straight for 2 seconds and stops.

Button B

Cycle SPEED

Steps SPEED from 1 → 2 → … → 20 → back to 1 without re-flashing. Shows new value on LED.

A + B

Emergency stop

Immediately cuts both motors during a run. Shows X on LED and clears after 500 ms.

💡
Show SPEED
Scrolls SPEED value on LED — 800 ms
→
⚡
Power bar
Bar graph shows motor % — 800 ms
→
⏸️
Pause
Screen clears — 500 ms
→
🤖
Drive
Both motors at currentPower for 2 000 ms
→
✋
Stop
Both motors cut immediately
→
🏁
Done
X pattern 500 ms then clear
ℹ️
The preview phase (SPEED scroll + power bar) takes about 2.1 seconds before the bot moves. The 2-second drive timer starts the moment wheels begin turning.
8
Scrolling number
Current SPEED stat — shown for 800 ms before each run, and when cycling with Button B
Bar graph
Height shows motor power (0–100%). Taller = more power. Shown for 800 ms after SPEED number
X pattern
Run complete or emergency stop triggered. Shown for 500 ms then clears
Motor Power
currentPower = (SPEED × 100) / 20 (%)
Both left and right motors get the same value, so the bot drives straight.
Starting Values
Loading blocks…
let testStart = 0
let running = false
let currentPower = 0
let SPEED = 1
let TEST_DURATION_MS = 2000
            
Set TEST_DURATION_MS to 2000 and SPEED to 1 before you download. Everything else starts at 0 and gets computed when you press A.
Button A — Run the test
Loading blocks…
let currentPower = 0
let SPEED = 0
let running = false
let testStart = 0
let TEST_DURATION_MS = 0
input.onButtonPressed(Button.A, function () {
    currentPower = SPEED * 100 / 20
    basic.showString("" + (SPEED))
    basic.pause(800)
    led.plotBarGraph(
    currentPower,
    100
    )
    basic.pause(800)
    basic.clearScreen()
    basic.pause(500)
    running = true
    testStart = input.runningTime()
    CutebotPro.pwmCruiseControl(currentPower, currentPower)
    while (running && input.runningTime() - testStart < TEST_DURATION_MS) {
        CutebotPro.pwmCruiseControl(currentPower, currentPower)
    }
    CutebotPro.stopImmediately(CutebotProMotors.ALL)
    running = false
    basic.showLeds(`
        # . . . #
        . # . # .
        . . # . .
        . # . # .
        # . . . #
        `)
    basic.pause(500)
    basic.clearScreen()
})
            
Computes currentPower from your SPEED stat, shows the number then the power bar, then drives straight for TEST_DURATION_MS milliseconds. The while loop keeps checking elapsed time so an A+B press can exit early. X pattern on LED confirms the run is done.
Button B — Cycle SPEED
Loading blocks…
let SPEED = 0
input.onButtonPressed(Button.B, function () {
    if (SPEED >= 20) {
        SPEED = 1
    } else {
        SPEED += 1
    }
    basic.showString("" + (SPEED))
    basic.clearScreen()
})
            
Steps SPEED up by 1 each press — wraps back to 1 after 20. The scrolling number lets you confirm the value before pressing A. No re-flashing needed.
Button A+B — Emergency Stop
Loading blocks…
let running = false
input.onButtonPressed(Button.AB, function () {
    running = false
    CutebotPro.stopImmediately(CutebotProMotors.ALL)
    basic.showLeds(`
        # . . . #
        . # . # .
        . . # . .
        . # . # .
        # . . . #
        `)
    basic.pause(500)
    basic.clearScreen()
})
            
Sets running = false so the Button A loop exits on its next check, then cuts both motors immediately. Use this if the bot heads somewhere it shouldn't.
Try a SPEED value Mirrors what the bot computes on Button A
SPEED 10
Press B on the micro:bit v2 to cycle this same range live without re-flashing
Motor Power
50%
both motors
Drive Duration
2.0
seconds
Preview Time
~2.1
sec (scroll + bar)
Motor power — 50%
0% 25% 50% 75% 100%

Button B changes SPEED in memory without touching the flashed program. Each press adds 1 to SPEED. When SPEED hits 20, the next press wraps it back to 1.

1 → 2 → · · · → 20 → 1 → · · ·
ℹ️
The new SPEED only takes effect the next time you press A. Pressing B mid-run changes the value in memory but doesn't affect the current drive — currentPower was already computed when you pressed A.
NameValuePurpose
SPEED 1 Starting speed stat — set to 1 in code before downloading, then cycle with Button B
TEST_DURATION_MS 2000 How long the bot drives on each press of A (milliseconds). Set this to 2000 in code before downloading
currentPower computed (SPEED × 100)/20 — the actual PWM value sent to both motors
running false Flag that the A+B emergency stop sets to false, causing the drive loop to exit
testStart computed Timestamp (ms) when the drive loop begins — used to measure elapsed time
  1. 1 Set TEST_DURATION_MS to 2000 and SPEED to 1 in the code. Then download the program.
  2. 2 Set a SPEED with Button B. Each press adds 1. The scrolling number confirms the current value. Stop when you reach the stat you want to test.
  3. 3 Place the bot on a clear straight run. It drives for 2 seconds then stops. Mark where it starts and where ends up.
  4. 4 Press A to run. Watch the preview (number → bar graph), then it drives. Press A+B any time to stop early.
  5. 5 Compare speeds. Press B to bump SPEED up, reposition the bot at the same start line, press A again. Compare how far it travels.
⚠️
The bot has no sensors active during this test. It drives blind for 2 seconds. Make sure the run path is clear — it will drive off a table or into a wall without stopping.