Microbit LED 矩阵
The Microbit_LED
extension provides App Inventor users with the ability to programmatically change the BBC micro:bit’s 5x5 LED matrix, either by coding custom patterns or writing text strings. The scrolling speed of the display may also be customized.
More links:<ul><li>Download a sample projects for the micro:bit LED matrix.</li><li>View the how to instructions for the micro:bit LED matrix.</li></ul>
Properties
Methods
ReadLEDMatrixState
– Read the current state of the LED matrix from the micro:bit. The LED matrix state will be reported through theLEDMatrixStateReceived
event.
ReadScrollingDelay
– Read the current scroll delay for the micro:bit’s LED matrix. After a successful read, theScrollingDelayReceived
event will be run.
WriteLEDMatrixState
– Write the state of the micro:bit’s LED matrix.LED_Matrix_State
should be a list of 5 numbers from 0-31 to indicate which LEDs should be turned on in each of the 5 rows of the LED matrix. From left to right, the values of the LEDs are 16, 8, 4, 2, 1. For example, if you want to turn on the LEDs in one row such that power states were 10011, you would send the value (16 + 2 + 1) or 19 for the row. After the write operation completes, theWroteLEDMatrixState
event will be run.
Parameters:
* <code>LED_Matrix_State</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#makealist">_list_</a>) — A list of 5 numbers, one for each row of the LED matrix, where each
value is the integer value of the bit array for the nth row of the LED matrix.
WriteLEDText
– Write text to the micro:bit’s LED matrix. The rate at which each character appears on the micro:bit’s display depends on the last scroll value written byWriteScrollDelay
. Due to the allowable length of Bluetooth low energy packets, the strings sent are restricted to 20 or more UTF-8 octets. Attempts to write strings longer than 20 octets will result in truncated messages.
Parameters:
+ <code>LED_Text_Value</code> (_string_) — The text to write. Strings are limited to
a length of 20 UTF-8 octets.
WriteScrollingDelay
– Set the delay between characters displayed on the micro:bit’s LED matrix, in milliseconds. After writing the value, theWriteScrollingDelay
will be called.
Parameters:
* <code>Scrolling_Delay_Value</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/math.html#number">_number_</a>) — The delay between characters on the LED matrix, in milliseconds.
Events
LEDMatrixStateReceived
– TheLEDMatrixStateReceived
event is run when the state of the micro:bit’s LED matrix is read from the device. TheLED_Matrix_State
is a list of 5 values, one for each row of the matrix. Each value is an number from 0-31. From left to right, the LEDs are valued 16, 8, 4, 2, 1.
Parameters:
+ <code>LED_Matrix_State</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#makealist">_list_</a>) — A list of 5 values, one for each row, with
each value being between 0-31 to indicate which LEDs in that row are on.
ScrollingDelayReceived
– TheScrolling_Delay_Value
event will be run after requesting the scrolling delay for the micro:bit’s LED matrix through the <a href=”#ReadScrollingDelay>ReadScrollingDelay
</a> method.
Parameters:
* <code>Scrolling_Delay_Value</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/math.html#number">_number_</a>) — The delay between characters on the LED matrix, in milliseconds.
WroteLEDMatrixState
– TheWriteLEDMatrixState
event will be run after the micro:bit’s LED matrix is written due to a call toWriteLEDMatrixState
. The LED_Matrix_State will be the same as in the call toWriteLEDMatrixState
to differentiate the response to potentially many calls to write the LED matrix.
Parameters:
* <code>LED_Matrix_State</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#makealist">_list_</a>) — The values written to the LED matrix as specified in the previous call
to
WroteLEDText
– TheWroteLEDText
event will be run after text is written to the micro:bit’s LED matrix through a call toWriteLEDText
. The value of the written text will be given by theLED_Text_Value
parameter.
Parameters:
* <code>LED_Text_Value</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) — The text to write to the LED matrix.
WroteScrollingDelay
– TheWroteScrollingDelay
event will be run after the micro:bit’s scrolling delay is successfully read after a call to theWriteScrollingDelay
method.
Parameters:
* <code>Scrolling_Delay_Value</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/math.html#number">_number_</a>) — The delay between characters on the LED matrix, in milliseconds.