This program drives the bot straight for 2 seconds at whatever SPEED you've set — so you can see how far it travels at different motorPower values. Press B to cycle through your stat SPEED without re-flashing.
Shows SPEED stat and power bar, then drives straight for 2 seconds and stops.
Steps SPEED from 1 → 2 → … → 20 → back to 1 without re-flashing. Shows new value on LED.
Immediately cuts both motors during a run. Shows X on LED and clears after 500 ms.
let testStart = 0
let running = false
let currentPower = 0
let SPEED = 1
let TEST_DURATION_MS = 2000
TEST_DURATION_MS to 2000 and SPEED to 1 before you download. Everything else starts at 0 and gets computed when you press A.
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()
})
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.
let SPEED = 0
input.onButtonPressed(Button.B, function () {
if (SPEED >= 20) {
SPEED = 1
} else {
SPEED += 1
}
basic.showString("" + (SPEED))
basic.clearScreen()
})
let running = false
input.onButtonPressed(Button.AB, function () {
running = false
CutebotPro.stopImmediately(CutebotProMotors.ALL)
basic.showLeds(`
# . . . #
. # . # .
. . # . .
. # . # .
# . . . #
`)
basic.pause(500)
basic.clearScreen()
})
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.
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.
currentPower was already computed when you pressed A.