Cover image
    Activity

    Code a micro:bit to Loop Over a List of Positions

    Iterate over a range of positions.

    Coding
    Get Started
    8-14+
    40:00
    micro:bit Coding Cards

    Code

    Loop Over a List of Positions

    00:10

    Create a list of positions and then continuously loop through them and set their value as the position to the Servo A.

    let list = [0, 50, 100]
    basic.forever(function () {
        for (let value of list) {
            sb.setServoPosition(sb.servo(SBServo.ServoA), value)
            basic.pause(1000)
        }
    })

    If using micro:bit for the first time, follow this setup.