Cover image
    Activity

    Code a micro:bit to Sweep Motor

    Watch a fluid, sweeping animation with the servo.

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

    Code

    Sweep Motor

    00:10

    Continuously iterate over a number from 0 to 100 and use it to set the position of the Servo A.

    basic.forever(function () {
        for (let index = 0; index <= 100; index++) {
            sb.setServoPosition(sb.servo(SBServo.ServoA), index)
            basic.pause(100)
        }
    })

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