-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enumSpecifies which mode should be used while scrolling the LED matrix.static enumMapping of various symbols to their respective 8x8 encoding. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intDefault SPI baud rate for the LED matrix on the CrowPiprotected static final intDefault SPI channel for the LED matrix on the CrowPiprotected static final longDefault delay between scroll operations in millisecondsprotected static final DirectionDefault direction for scroll operations -
Constructor Summary
ConstructorsConstructorDescriptionLedMatrixComponent(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.voiddraw(BufferedImage image) Displays the givenBufferedImageon the LED matrix by enabling LEDs for non-black colors.voiddraw(BufferedImage image, int x, int y) Displays a specific area of the givenBufferedImageon the LED matrix by enabling LEDs for non-black colors.voiddraw(Consumer<Graphics2D> drawer) Initializes a blank image with the same size as the LED matrix and calls the given consumer with aGraphics2Dinstance.protected com.pi4j.io.spi.SpigetSpi()Returns the current SPI instance for the LED matrix.protected LedMatrixComponent.SymbollookupSymbol(char c) Returns aLedMatrixComponent.Symbolwhich is associated with the given ASCII character.voidprint(char c) Prints the given character on the LED matrix, which will be immediately displayed.voidprint(LedMatrixComponent.Symbol symbol) Prints the given symbol on the LED matrix, which will be immediately displayed.voidPrints the given string to the LED matrix by scrolling each character in from left to right with the default scroll delay.voidPrints the given string to the LED matrix by scrolling each character in towards the given direction with the default scroll delay.voidPrints the given string to the LED matrix by scrolling each character in towards the given direction with a custom scroll delay.voidRotates the display towards the given direction and wraps around the affected row/column.voidScrolls the display towards the given direction and leaves the now empty row/column empty.protected voidscroll(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.voidtransition(LedMatrixComponent.Symbol symbol) Transitions the current LED matrix display to the given symbol by gradually scrolling the symbol in.voidtransition(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.voidtransition(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, setTestModeMethods 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.LEFTis 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.HEARTsymbol. 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.HEARTsymbol. 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.HEARTsymbol. 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, anIllegalArgumentExceptionwill 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.LEFTmeans 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.LEFTmeans the new symbol scrolls in from right towards leftscrollDelay- Delay in milliseconds between each scrolled column
-
lookupSymbol
Returns aLedMatrixComponent.Symbolwhich is associated with the given ASCII character. Throws anIllegalArgumentExceptionif 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 aGraphics2Dinstance. 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 givenBufferedImageon 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 aRasterFormatExceptionwill 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 givenBufferedImageon 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
-