Class MAX7219

java.lang.Object
com.pi4j.crowpi.components.Component
com.pi4j.crowpi.components.internal.MAX7219
Direct Known Subclasses:
LedMatrixComponent

public class MAX7219 extends Component
Implementation of MAX7219 driver chip used for 8x8 LED matrix displays. Uses SPI via Pi4J for controlling the chip programmatically.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected 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 column
    static final int
    Height of MAX7219 LED matrix
    protected final com.pi4j.io.spi.Spi
    Pi4J SPI instance
    static final int
    Width of MAX7219 LED matrix

    Fields inherited from class com.pi4j.crowpi.components.Component

    logger
  • Constructor Summary

    Constructors
    Constructor
    Description
    MAX7219(com.pi4j.io.spi.Spi spi)
    Creates a new MAX7219 instance using the given SPI instance from Pi4J.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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
    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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • WIDTH

      public static final int WIDTH
      Width of MAX7219 LED matrix
      See Also:
    • HEIGHT

      public static final int HEIGHT
      Height of MAX7219 LED matrix
      See Also:
    • buffer

      protected final byte[] buffer
      Internal 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 spi
      Pi4J 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 until refresh() 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 (including setEnabled(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 until refresh() or refreshRow(int) gets called.
      Parameters:
      x - X position to change
      y - Y position to change
      enabled - 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 change
      y - Y position to change
      Returns:
      Current state of specified pixel (true = ON, false = OFF)