java.lang.Object
com.pi4j.crowpi.components.Component
com.pi4j.crowpi.components.internal.MAX7219
- Direct Known Subclasses:
LedMatrixComponent
Implementation of MAX7219 driver chip used for 8x8 LED matrix displays.
Uses SPI via Pi4J for controlling the chip programmatically.
-
Field Summary
Modifier and TypeFieldDescriptionprotected final byte[]
Internal buffer to store the 8x8 matrix A byte[] array is used as each of the 8 bits is used to represent a columnstatic final int
Height of MAX7219 LED matrixprotected final com.pi4j.io.spi.Spi
Pi4J SPI instancestatic final int
Width of MAX7219 LED matrix -
Constructor Summary
ConstructorDescriptionMAX7219
(com.pi4j.io.spi.Spi spi) Creates a new MAX7219 instance using the given SPI instance from Pi4J. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears the internal buffer without refreshing the display.boolean
getPixel
(int x, int y) Retrieves the pixel at the given X/Y position within the internal buffer.void
refresh()
Flushes the internal buffer for all rows to the chip, causing it to be displayed.protected void
refreshRow
(int row) Flushes the internal buffer for a single row to the chip, causing it to be displayed.void
setBrightness
(int brightness) Changes the desired brightness for the LED matrix.void
setEnabled
(boolean enabled) Specifies if the LED matrix should be enabled or disabled.void
setPixel
(int x, int y, boolean enabled) Enables or disables the pixel at the given X/Y position within the internal buffer.void
setTestMode
(boolean enabled) Enables or disables the testing mode of the LED matrix.Methods inherited from class com.pi4j.crowpi.components.Component
sleep, triggerSimpleEvent
-
Field Details
-
WIDTH
public static final int WIDTHWidth of MAX7219 LED matrix- See Also:
-
HEIGHT
public static final int HEIGHTHeight of MAX7219 LED matrix- See Also:
-
buffer
protected final byte[] bufferInternal buffer to store the 8x8 matrix A byte[] array is used as each of the 8 bits is used to represent a column -
spi
protected final com.pi4j.io.spi.Spi spiPi4J SPI instance
-
-
Constructor Details
-
MAX7219
public MAX7219(com.pi4j.io.spi.Spi spi) Creates a new MAX7219 instance using the given SPI instance from Pi4J.- Parameters:
spi
- SPI instance
-
-
Method Details
-
clear
public void clear()Clears the internal buffer without refreshing the display. This means that the current contents of the displays are still being shown untilrefresh()
is called. -
refresh
public void refresh()Flushes the internal buffer for all rows to the chip, causing it to be displayed. The contents of the buffer will be preserved by this command. -
refreshRow
protected void refreshRow(int row) Flushes the internal buffer for a single row to the chip, causing it to be displayed. The contents of the buffer will be preserved by this command.- Parameters:
row
- Row to be flushed
-
setEnabled
public void setEnabled(boolean enabled) Specifies if the LED matrix should be enabled or disabled. This will also setup the proper decoding mode and scan limit when enabling the chip.- Parameters:
enabled
- LED matrix state (true = ON, false = OFF)
-
setTestMode
public void setTestMode(boolean enabled) Enables or disables the testing mode of the LED matrix. When enabled, all other options (includingsetEnabled(boolean)
are ignored and all LEDs are turned on. To actually control the chip, the test mode MUST be disabled.- Parameters:
enabled
- Test mode state (true = ON, false = OFF)
-
setBrightness
public void setBrightness(int brightness) Changes the desired brightness for the LED matrix. This method expects an integer value within the range 0-15, with 0 being the dimmest and 15 the brightest possible value. The whole display is affected by this command which gets immediately applied.- Parameters:
brightness
- Desired brightness from 0-15
-
setPixel
public void setPixel(int x, int y, boolean enabled) Enables or disables the pixel at the given X/Y position within the internal buffer. This change will not be visible untilrefresh()
orrefreshRow(int)
gets called.- Parameters:
x
- X position to changey
- Y position to changeenabled
- Desired pixel state (true = ON, false = OFF)
-
getPixel
public boolean getPixel(int x, int y) Retrieves the pixel at the given X/Y position within the internal buffer.- Parameters:
x
- X position to changey
- Y position to change- Returns:
- Current state of specified pixel (true = ON, false = OFF)
-