Cover image
    Activity

    Code Two micro:bits as a Color Remote Controller

    Use two micro:bits, with one acting as a sender of radio values and the other as a receiver, to change color.

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

    Code

    Color Remote Controller

    00:10

    Sender

    Set the radio group to 1, to connect with the receiver, the second micro:bit. Continuously check if Button A is pressed then send a radio signal with the name light and the value 100 to turn the light on or as 0 to turn off.

    radio.setGroup(1)
    basic.forever(function () {
        if (input.buttonIsPressed(Button.A)) {
            radio.sendValue("light", 100)
        } else {
            radio.sendValue("light", 0)
        }
    })

    Receiver

    Set the radio group to 1, to connect with the sender. Monitor the incoming radio signals named light and use value to set one of the components of the RGB LED A color.

    radio.onReceivedValue(function (name, value) {
        if (name == "light") {
            sb.setRgbLedColorRGB(sb.rgbLed(SBRgbLed.RgbLedA), 0, value, 0)
        }
    })
    radio.setGroup(1)

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