leddisplay
LedDisplay #
A class representing the LED screen of the micro:bit. The LED on the top left of the micro:bit is the LED on row 1, column 1 The bottom right LED on the micro:bit is the LED in row 5, column 5
Source code in src/kaspersmicrobit/services/leddisplay.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
__init__ #
__init__(_bytes: bytearray = None)
Create a display with all LEDs off
Source code in src/kaspersmicrobit/services/leddisplay.py
16 17 18 19 20 |
|
led #
led(row: int, column: int) -> bool
Indicates whether an LED on the given row and column is on or off
Parameters:
-
row
(int
) –the row of the LED (valid values are 1 to 5)
-
column
(int
) –the column of the LED (valid values are 1 to 5)
Returns:
-
bool
–True when the LED is on, False when the LED is off
Source code in src/kaspersmicrobit/services/leddisplay.py
22 23 24 25 26 27 28 29 30 31 32 33 |
|
set_led #
set_led(row: int, column: int, on: bool = True)
Turn an LED on or off on the given row and column
Parameters:
-
row
(int
) –the row of the LED (valid values are 1 to 5)
-
column
(int
) –the column of the LED (valid values are 1 to 5)
-
on
(bool
, default:True
) –if True the LED is turned on, if False it is turned off
Source code in src/kaspersmicrobit/services/leddisplay.py
35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
image
staticmethod
#
image(
string: str, on: str = "#", off: str = "."
) -> LedDisplay
Creates an LedDisplay given a string.
Example:
HEART: LedDisplay = LedDisplay.image('''
. # . # .
# # # # #
# # # # #
. # # # .
. . # . .
''')
You can choose which characters are used for an LED that is 'on' or 'off' with the 'on' and 'off' parameters. The given string must contain exactly 25 'on' and 'off' values, 1 for each LED.
Parameters:
-
string
(str
) –the string representing the LED screen
-
on
(str
, default:'#'
) –the letter representing an LED that is 'on' ('#' if left blank)
-
off
(str
, default:'.'
) –the letter representing an LED that is 'off' ('.' if left blank)
Returns:
-
LedDisplay
–An LedDisplay representing the given string image
Raises:
-
ValueError
–If the given string does not contain exactly 25 on/off values
Source code in src/kaspersmicrobit/services/leddisplay.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
|