-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static enum
Specifies which mode should be used while scrolling the LED matrix.static enum
Mapping of various symbols to their respective 8x8 encoding. -
Field Summary
Modifier and TypeFieldDescriptionprotected static final int
Default SPI baud rate for the LED matrix on the CrowPiprotected static final int
Default SPI channel for the LED matrix on the CrowPiprotected static final long
Default delay between scroll operations in millisecondsprotected static final Direction
Default direction for scroll operations -
Constructor Summary
ConstructorDescriptionLedMatrixComponent
(com.pi4j.context.Context pi4j) Creates a new LED matrix component with the default channel and baud rate.LedMatrixComponent
(com.pi4j.context.Context pi4j, int channel, int baud) Creates a new LED matrix component with a custom channel and baud rate. -
Method Summary
Modifier and TypeMethodDescriptionprotected List<LedMatrixComponent.Symbol>
convertToSymbols
(String string) Converts a string into a list of symbols to print on the 8x8 LED matrix.void
draw
(BufferedImage image) Displays the givenBufferedImage
on the LED matrix by enabling LEDs for non-black colors.void
draw
(BufferedImage image, int x, int y) Displays a specific area of the givenBufferedImage
on the LED matrix by enabling LEDs for non-black colors.void
draw
(Consumer<Graphics2D> drawer) Initializes a blank image with the same size as the LED matrix and calls the given consumer with aGraphics2D
instance.protected com.pi4j.io.spi.Spi
getSpi()
Returns the current SPI instance for the LED matrix.protected LedMatrixComponent.Symbol
lookupSymbol
(char c) Returns aLedMatrixComponent.Symbol
which is associated with the given ASCII character.void
print
(char c) Prints the given character on the LED matrix, which will be immediately displayed.void
print
(LedMatrixComponent.Symbol symbol) Prints the given symbol on the LED matrix, which will be immediately displayed.void
Prints the given string to the LED matrix by scrolling each character in from left to right with the default scroll delay.void
Prints the given string to the LED matrix by scrolling each character in towards the given direction with the default scroll delay.void
Prints the given string to the LED matrix by scrolling each character in towards the given direction with a custom scroll delay.void
Rotates the display towards the given direction and wraps around the affected row/column.void
Scrolls the display towards the given direction and leaves the now empty row/column empty.protected void
scroll
(Direction direction, LedMatrixComponent.ScrollMode scrollMode, byte[] newBuffer, int newOffset) Scrolls the display towards the given direction and fills the empty row/column based on scroll mode.void
transition
(LedMatrixComponent.Symbol symbol) Transitions the current LED matrix display to the given symbol by gradually scrolling the symbol in.void
transition
(LedMatrixComponent.Symbol symbol, Direction scrollDirection) Transitions the current LED matrix display to the given symbol by gradually scrolling the symbol in with the default scroll delay.void
transition
(LedMatrixComponent.Symbol symbol, Direction scrollDirection, long scrollDelay) Transitions the current LED matrix display to the given symbol by gradually scrolling the symbol in.Methods inherited from class com.pi4j.crowpi.components.internal.MAX7219
clear, getPixel, refresh, refreshRow, setBrightness, setEnabled, setPixel, setTestMode
Methods inherited from class com.pi4j.crowpi.components.Component
sleep, triggerSimpleEvent
-
Field Details
-
DEFAULT_CHANNEL
protected static final int DEFAULT_CHANNELDefault SPI channel for the LED matrix on the CrowPi- See Also:
-
DEFAULT_BAUD_RATE
protected static final int DEFAULT_BAUD_RATEDefault SPI baud rate for the LED matrix on the CrowPi- See Also:
-
DEFAULT_SCROLL_DELAY
protected static final long DEFAULT_SCROLL_DELAYDefault delay between scroll operations in milliseconds- See Also:
-
DEFAULT_SCROLL_DIRECTION
Default direction for scroll operations
-
-
Constructor Details
-
LedMatrixComponent
public LedMatrixComponent(com.pi4j.context.Context pi4j) Creates a new LED matrix component with the default channel and baud rate.- Parameters:
pi4j
- Pi4J context
-
LedMatrixComponent
public LedMatrixComponent(com.pi4j.context.Context pi4j, int channel, int baud) Creates a new LED matrix component with a custom channel and baud rate.- Parameters:
pi4j
- Pi4J contextchannel
- SPI channelbaud
- SPI baud rate
-
-
Method Details
-
scroll
Scrolls the display towards the given direction and leaves the now empty row/column empty.- Parameters:
direction
- Desired scroll direction
-
rotate
Rotates the display towards the given direction and wraps around the affected row/column. E.g. ifDirection.LEFT
is used, the column which falls out on the left will be the new rightmost column.- Parameters:
direction
- Desired scroll direction
-
scroll
protected void scroll(Direction direction, LedMatrixComponent.ScrollMode scrollMode, byte[] newBuffer, int newOffset) Scrolls the display towards the given direction and fills the empty row/column based on scroll mode. This helper method calls the appropriate internal functions and MUST not be exposed as it contains internal logic. The scrolling operating will be immediately visible on the display.- Parameters:
direction
- Desired scroll directionscrollMode
- Desired scroll modenewBuffer
- Only ifLedMatrixComponent.ScrollMode.REPLACE
: New buffer for replacement valuesnewOffset
- Only ifLedMatrixComponent.ScrollMode.REPLACE
: Desired row/column offset for new buffer
-
print
Prints the given string to the LED matrix by scrolling each character in from left to right with the default scroll delay. This method is blocking until the string has been fully printed and will both start and end with an empty display.A pattern in the format "{SYMBOL-NAME}" can be used to include a symbol with the given name in the string. E.g. if "{HEART}" occurs within the string, it will be automatically replaced with the
LedMatrixComponent.Symbol.HEART
symbol. If a pattern includes a symbol which could not be found, it is silently ignored and added as-is.- Parameters:
string
- String to be displayed
-
print
Prints the given string to the LED matrix by scrolling each character in towards the given direction with the default scroll delay. This method is blocking until the string has been fully printed and will both start and end with an empty display.A pattern in the format "{SYMBOL-NAME}" can be used to include a symbol with the given name in the string. E.g. if "{HEART}" occurs within the string, it will be automatically replaced with the
LedMatrixComponent.Symbol.HEART
symbol. If a pattern includes a symbol which could not be found, it is silently ignored and added as-is.- Parameters:
string
- String to be displayedscrollDirection
- Direction towards character should be scrolled in
-
print
Prints the given string to the LED matrix by scrolling each character in towards the given direction with a custom scroll delay. This method is blocking until the string has been fully printed and will both start and end with an empty display.A pattern in the format "{SYMBOL-NAME}" can be used to include a symbol with the given name in the string. E.g. if "{HEART}" occurs within the string, it will be automatically replaced with the
LedMatrixComponent.Symbol.HEART
symbol. If a pattern includes a symbol which could not be found, it is silently ignored and added as-is.- Parameters:
string
- String to be displayedscrollDirection
- Direction towards character should be scrolled inscrollDelay
- Delay in milliseconds between scroll operations
-
convertToSymbols
Converts a string into a list of symbols to print on the 8x8 LED matrix. Any characters not supported by the symbol table will throw anIllegalArgumentException
.This method will also search for Symbol reference patterns in the provided string, which are represented as "{SYMBOL-NAME}". If this pattern is found within the string, this method will try to lookup the symbol and if found add it instead of the pattern. If no symbol with a given name is found, it gets silently ignored and added as-is to the list of output symbols.
- Parameters:
string
- String to parse and convert to symbols- Returns:
- List of symbols to print for representing the given string
-
print
public void print(char c) Prints the given character on the LED matrix, which will be immediately displayed. If no symbol associated with the given character can be found, anIllegalArgumentException
will be thrown.- Parameters:
c
- Character to display
-
print
Prints the given symbol on the LED matrix, which will be immediately displayed.- Parameters:
symbol
- Symbol to display
-
transition
Transitions the current LED matrix display to the given symbol by gradually scrolling the symbol in. This works by scrolling each column in one-by-one towards the default scroll direction with the default scroll delay.- Parameters:
symbol
- New symbol to display
-
transition
Transitions the current LED matrix display to the given symbol by gradually scrolling the symbol in with the default scroll delay. This works by scrolling each column in one-by-one towards the given scroll direction with the default scroll delay.- Parameters:
symbol
- New symbol to displayscrollDirection
- Desired scrolling direction, e.g.Direction.LEFT
means the new symbol scrolls in from right towards left
-
transition
public void transition(LedMatrixComponent.Symbol symbol, Direction scrollDirection, long scrollDelay) Transitions the current LED matrix display to the given symbol by gradually scrolling the symbol in. This works by scrolling each column in one-by-one towards the given scroll direction with the specified scroll delay.- Parameters:
symbol
- New symbol to displayscrollDirection
- Desired scrolling direction, e.g.Direction.LEFT
means the new symbol scrolls in from right towards leftscrollDelay
- Delay in milliseconds between each scrolled column
-
lookupSymbol
Returns aLedMatrixComponent.Symbol
which is associated with the given ASCII character. Throws anIllegalArgumentException
if no symbol associated with this character was found.- Parameters:
c
- Character to lookup- Returns:
- Symbol associated to character
-
draw
Initializes a blank image with the same size as the LED matrix and calls the given consumer with aGraphics2D
instance. This allows to easily draw on the screen using regular drawing commands likeGraphics.drawLine(int, int, int, int)
. The drawn image will be immediately displayed on the LED matrix.- Parameters:
drawer
- Lambda function which draws on new image
-
draw
Displays a specific area of the givenBufferedImage
on the LED matrix by enabling LEDs for non-black colors. The area will start at the given X/Y position and has the same width and height as the LED matrix. You MUST ensure that the full width/height is still within bounds or aRasterFormatException
will be thrown. The drawn image will be immediately displayed on the LED matrix.- Parameters:
image
- Image to partially display on the LED matrixx
- X coordinate where visible area should starty
- Y coordinate where visible area should start
-
draw
Displays the givenBufferedImage
on the LED matrix by enabling LEDs for non-black colors. The passed image MUST have the same size as the LED matrix and of typeBufferedImage.TYPE_BYTE_BINARY
. Use the overloaded methoddraw(BufferedImage, int, int)
to only display a specific area of a bigger image. The drawn image will be immediately displayed on the LED matrix.- Parameters:
image
- Image to display on the LED matrix
-
getSpi
protected com.pi4j.io.spi.Spi getSpi()Returns the current SPI instance for the LED matrix.- Returns:
- SPI instance
-