Main Content

writeLED

Write to BBC micro:bit LED

Description

writeLED(microbitObj,data) displays data on BBC micro:bit board LED matrix or flashes a specific LED, using a microbit object.

example

writeLED(microbitObj,data,Name,Value) displays data on BBC micro:bit board LED Matrix or flashes a specific LED, using a microbit object, with an additional option to include the scrolling speed as a name-value pair.

Examples

collapse all

Write "X" on the LED matrix of BBC micro:bit hardware connected to the COM4 port, and define the scrolling speed as 5 columns per second (scrolling speed as 5).

m = microbit('COM4');
data = [1 0 0 0 1;0 1 0 1 0;0 0 1 0 0;0 1 0 1 0;1 0 0 0 1];
writeLED(m,data,'ScrollingSpeed',5);

Input Arguments

collapse all

BBC micro:bit hardware connection, specified as a microbit object.

Data to be displayed on the LED matrix. Valid inputs are:

  • character string — Lights the LEDs based on the text or character mentioned.

  • scalar — Lights a single LED using linear addressing.

  • vector — Lights a single LED, defined using a 1-by-2 vector that gives the horizontal and vertical coordinates of the LED to be lit.

  • matrix — One of the following:

    • MATLAB® matrix functions like ones, eye, and so on, which represent a pattern of ones in an array. A limit of 5-by-5 needs to be considered if you are using these functions to create the matrix.

    • A 5-by-n matrix, where n ≥ 5, and the matrices created using MATLAB functions like horzcat, which represent concatenation of arrays. You need to specify the scrolling speed so that all the columns scroll in the display.

    Note

    In the matrix, a value of 0 indicates that the LED is off, and a value of 1 indicates that the LED is on.

  • MicrobitImages.image name — An image from the BBC micro:bit library. The following table shows the supported names of images based on the category.

    Image Names

    CategoryName of Image
    FaceHappyFaceSadFace
    NeutralFaceShockedFace
    SurprisedFace 
    Arrow with directionArrowNorthArrowNorthEast
    ArrowEastArrowSouthEast
    ArrowSouthArrowSouthWest
    ArrowWestArrowNorthWest
    DiceOneOnDiceTwoOnDice
    ThreeOnDiceFourOnDice
    FiveOnDiceSixOnDice
    All upper case lettersA ….…... Z
    All lower case lettersa ….….…. z
    All single digit numbersZero One Two .….. Nine
    HeartHeartFilledHeart

Note

Float data types like single and double are not supported for the data argument.

Example: writeLED(m,"THIS is micro:bit", 'ScrollingSpeed', 5)

Example: writeLED(m, '>')

Example: writeLED(m, 'M')

Example: writeLED(m,7)

Example: writeLED(m,[2 2])

Example: writeLED(m, eye(5))

Example: writeLED(m, horzcat(eye(5),ones(5)), 'ScrollingSpeed', 4)

Example: writeLED(m, MicrobitImages.Heart)

Example: writeLED(m, MicrobitImages.M)

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: writeLED(obj,data,'ScrollingSpeed',3)

The name-value pair arguments for writeLED are included after obj and data inputs.

Scrolling speed of the LED display on the BBC micro:bit board.

Version History

Introduced in R2017b

See Also

|