Cover image
    Activity

    Code a micro:bit to Change Color 10 Times

    Alternate between colors before switching off.

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

    Code

    Change Color 10 Times

    00:10

    Alternate between two colors of the RGB LED A, on repeat 10 times before turning it off.

    for (let index = 0; index < 10; index++) {
        sb.setRgbLedColorRGB(sb.rgbLed(SBRgbLed.RgbLedA), 100, 0, 0)
        basic.pause(500)
        sb.setRgbLedColorRGB(sb.rgbLed(SBRgbLed.RgbLedA), 0, 0, 100)
        basic.pause(500)
    }
    sb.setRgbLedColorRGB(sb.rgbLed(SBRgbLed.RgbLedA), 0, 0, 0)

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