Cover image
    Activity

    Code a micro:bit to Shine in the Dark

    Luminate a single LED, casting a soft glow like a lone star in the night.

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

    Code

    Shine in the Dark

    00:15

    Use a forever loop to continuously check if the value of the built-in light sensor is below a threshold, and depending on it, turn the RGB LED A on or off.

    basic.forever(function () {
        if (input.lightLevel() < 50) {
            sb.setRgbLedColorRGB(sb.rgbLed(SBRgbLed.RgbLedA), 100, 0, 0)
        } else {
            sb.setRgbLedColorRGB(sb.rgbLed(SBRgbLed.RgbLedA), 0, 0, 0)
        }
    })

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