Cover image
    Activity

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

    Code continuous red, green, and blue cycles in an RGB LED with a short pause between each.

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

    Code

    Loop Over a List of Colors

    00:10

    Create a list of colors and then continuously loop through them and set their value to the RGB LED.

    let list = [sb.colorLabel(SBColor.Red), sb.colorLabel(SBColor.Green), sb.colorLabel(SBColor.Blue)]
    basic.forever(function () {
        for (let value of list) {
            sb.setRgbLedColor(sb.rgbLed(SBRgbLed.RgbLedA), value)
            basic.pause(1000)
        }
    })

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