Cover image
    Activity

    Code a micro:bit to Move Back and Forth

    Control a servo to sweep from one extreme position to the other, creating a smooth and rhythmic motion.

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

    Code

    Back and Forth

    00:10

    Continuously transition the Servo A position from one end to the other.

    basic.forever(function () {
        sb.transitionServoPosition(sb.servo(SBServo.ServoA), 0, 3, sb.easing(SBEasing.Linear))
        sb.transitionServoPosition(sb.servo(SBServo.ServoA), 100, 3, sb.easing(SBEasing.Linear))
    })

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