hub.light_matrix¶
The light_matrix module includes functions to interact with the 5x5 LED
matrix on the face of the SPIKE hubs.
To use the light_matrix module, add the following import statement to
your project:
from hub import light_matrix
All functions in the module should be called inside the light_matrix
module as a prefix like so:
light_matrix.write("Hello World")
The following constants are defined:
IMAGE_HEART= 1IMAGE_HEART_SMALL= 2IMAGE_HAPPY= 3IMAGE_SMILE= 4IMAGE_SAD= 5IMAGE_CONFUSED= 6IMAGE_ANGRY= 7IMAGE_ASLEEP= 8IMAGE_SURPRISED= 9IMAGE_SILLY= 10IMAGE_FABULOUS= 11IMAGE_MEH= 12IMAGE_YES= 13IMAGE_NO= 14IMAGE_CLOCK12= 15IMAGE_CLOCK1= 16IMAGE_CLOCK2= 17IMAGE_CLOCK3= 18IMAGE_CLOCK4= 19IMAGE_CLOCK5= 20IMAGE_CLOCK6= 21IMAGE_CLOCK7= 22IMAGE_CLOCK8= 23IMAGE_CLOCK9= 24IMAGE_CLOCK10= 25IMAGE_CLOCK11= 26IMAGE_ARROW_N= 27IMAGE_ARROW_NE= 28IMAGE_ARROW_E= 29IMAGE_ARROW_SE= 30IMAGE_ARROW_S= 31IMAGE_ARROW_SW= 32IMAGE_ARROW_W= 33IMAGE_ARROW_NW= 34IMAGE_GO_RIGHT= 35IMAGE_GO_LEFT= 36IMAGE_GO_UP= 37IMAGE_GO_DOWN= 38IMAGE_TRIANGLE= 39IMAGE_TRIANGLE_LEFT= 40IMAGE_CHESSBOARD= 41IMAGE_DIAMOND= 42IMAGE_DIAMOND_SMALL= 43IMAGE_SQUARE= 44IMAGE_SQUARE_SMALL= 45IMAGE_RABBIT= 46IMAGE_COW= 47IMAGE_MUSIC_CROTCHET= 48IMAGE_MUSIC_QUAVER= 49IMAGE_MUSIC_QUAVERS= 50IMAGE_PITCHFORK= 51IMAGE_XMAS= 52IMAGE_PACMAN= 53IMAGE_TARGET= 54IMAGE_TSHIRT= 55IMAGE_ROLLERSKATE= 56IMAGE_DUCK= 57IMAGE_HOUSE= 58IMAGE_TORTOISE= 59IMAGE_BUTTERFLY= 60IMAGE_STICKFIGURE= 61IMAGE_GHOST= 62IMAGE_SWORD= 63IMAGE_GIRAFFE= 64IMAGE_SKULL= 65IMAGE_UMBRELLA= 66IMAGE_SNAKE= 67SHOWING= 0 (UNDOCUMENTED)SUCCESS= 1 (UNDOCUMENTED)CANCELLED= 2 (UNDOCUMENTED)
Functions
|
Switch off all of the pixels on the Light Matrix. |
Get the current orientation of the Light Matrix. |
|
|
Get the intensity of a specific pixel on the Light Matrix. |
|
Set the orientation of the Light Matrix. |
|
Set the brightness of one pixel (one of the 25 LEDs) on the Light Matrix. |
|
Set all of the lights at the same time. |
|
Display one of the built-in images on the display. |
|
Display text on the Light Matrix, one letter at a time, scrolling from right to left if necessary. |
- hub.light_matrix.clear()¶
Switch off all of the pixels on the Light Matrix.
from hub import light_matrix import time # Update pixels to show an image on Light Matrix, and then turn # them off using the clear function # Show a small heart light_matrix.show_image(2) # Wait for two seconds time.sleep_ms(2000) # Switch off the heart light_matrix.clear()
- Return type:
None
- hub.light_matrix.get_orientation()¶
Get the current orientation of the Light Matrix. Can be used with the following constants:
orientation.UP,orientation.LEFT,orientation.RIGHT,orientation.DOWN- Return type:
int
- hub.light_matrix.get_pixel(x, y)¶
Get the intensity of a specific pixel on the Light Matrix.
from hub import light_matrix # Show a heart light_matrix.show_image(1) # Print the value of the center pixel's intensity print(light_matrix.get_pixel(2, 2))
- Parameters:
x (int) – The pixel column, range 0–4
y (int) – The pixel row, range 0–4
- Return type:
int
- hub.light_matrix.set_orientation(top)¶
Set the orientation of the Light Matrix. All subsequent calls will use the new orientation. Can be used with the following constants:
orientation.UP,orientation.LEFT,orientation.RIGHT,orientation.DOWN- Parameters:
top (int) – The side of the hub to be considered the top
- Return type:
int
- hub.light_matrix.set_pixel(x, y, intensity)¶
Set the brightness of one pixel (one of the 25 LEDs) on the Light Matrix.
from hub import light_matrix # Turn on the pixel in the center of the hub light_matrix.set_pixel(2, 2, 100)
- Parameters:
x (int) – The pixel column, range 0–4
y (int) – The pixel row, range 0–4
intensity (int) – How bright to light up the pixel
- Return type:
None
- hub.light_matrix.show(pixels)¶
Set all of the lights at the same time.
from hub import light_matrix # Update all pixels on Light Matrix using the show function # Create a list with 25 identical intensity values pixels = [100] * 25 # Update all pixels to show same intensity light_matrix.show(pixels)
- Parameters:
pixels (list[int]) – A list containing light intensity values for all 25 pixels
- Return type:
None
- hub.light_matrix.show_image(image)¶
Display one of the built-in images on the display.
from hub import light_matrix # Update pixels to show an image on Light Matrix using the # show_image function # Show a smiling face light_matrix.show_image(light_matrix.IMAGE_HAPPY)
- Parameters:
image (int) – The ID of the image to show. The range of available images is 1 to 67 (see the
light_matrixmodule for available constants).- Return type:
None
- hub.light_matrix.write(text, intensity=100, time_per_character=500)¶
Display text on the Light Matrix, one letter at a time, scrolling from right to left if necessary.
from hub import light_matrix # White a message to the hub light_matrix.write("Hello, world!")
- Parameters:
text (str) – The text to display
intensity (int) – How bright to light up the pixel
time_per_character (int) – How long to show each character on the display
- Return type:
Awaitable