MD_MAXPanel LED Matrix Panel Arduino Library  1.2
Library to control a panel of connected MAX72XX devices
MD_MAXPanel Class Reference

#include <MD_MAXPanel.h>

Public Types

enum  rotation_t { ROT_0, ROT_90, ROT_180, ROT_270 }
 

Public Member Functions

 MD_MAXPanel (MD_MAX72XX::moduleType_t mod, uint8_t dataPin, uint8_t clkPin, uint8_t csPin, uint8_t xDevices, uint8_t yDevices)
 
 MD_MAXPanel (MD_MAX72XX::moduleType_t mod, uint8_t csPin, uint8_t xDevices, uint8_t yDevices)
 
 MD_MAXPanel (MD_MAX72XX *D, uint8_t xDevices, uint8_t yDevices)
 
void begin (void)
 
 ~MD_MAXPanel ()
 
Methods for object management.
void clear (void)
 
void clear (uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, bool state=false)
 
MD_MAX72XX * getGraphicObject (void)
 
uint16_t getXMax (void)
 
uint16_t getYMax (void)
 
rotation_t getRotation (void)
 
void setRotation (rotation_t r)
 
void update (bool state)
 
void update ()
 
void setIntensity (uint8_t intensity)
 
Methods for drawing graphics.
bool drawHLine (uint16_t y, uint16_t x1, uint16_t x2, bool state=true)
 
bool drawLine (uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, bool state=true)
 
bool drawVLine (uint16_t x, uint16_t y1, uint16_t y2, bool state=true)
 
bool drawRectangle (uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, bool state=true)
 
bool drawFillRectangle (uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, bool state=true)
 
bool drawTriangle (uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t x3, uint16_t y3, bool state=true)
 
bool drawFillTriangle (uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t x3, uint16_t y3, bool state=true)
 
bool drawQuadrilateral (uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t x3, uint16_t y3, uint16_t x4, uint16_t y4, bool state=true)
 
bool drawCircle (uint16_t xc, uint16_t yc, uint16_t r, bool state=true)
 
bool drawFillCircle (uint16_t xc, uint16_t yc, uint16_t r, bool state=true)
 
bool getPoint (uint16_t x, uint16_t y)
 
bool setPoint (uint16_t x, uint16_t y, bool state=true)
 
Methods for Fonts and text.
void setFont (MD_MAX72XX::fontType_t *fontDef)
 
void setCharSpacing (uint8_t spacing)
 
uint8_t getCharSpacing (void)
 
uint16_t getTextWidth (const char *psz)
 
uint16_t getFontHeight (void)
 
uint16_t drawText (uint16_t x, uint16_t y, const char *psz, rotation_t rot=ROT_0, bool state=true)
 

Detailed Description

Core object for the MD_MAXPanel library

Member Enumeration Documentation

◆ rotation_t

Rotation enumerated type specification.

Used to define rotation orientation (eg, text or display). For text the normal rotation is the standard Latin language left to right orientation. Rotation is specified anchored to the first character of the string - 0 points >, 90 ^, 180 < and 270 v. For the display rotation 0 and 180 and are identical and 90 and 270 are identical. The rotation will shift the display between landscape and portrait mode.

Enumerator
ROT_0 

Rotation 0 degrees.

ROT_90 

Rotation 90 degrees.

ROT_180 

Rotation 180 degrees.

ROT_270 

Rotation 270 degrees.

Constructor & Destructor Documentation

◆ MD_MAXPanel() [1/3]

MD_MAXPanel::MD_MAXPanel ( MD_MAX72XX::moduleType_t  mod,
uint8_t  dataPin,
uint8_t  clkPin,
uint8_t  csPin,
uint8_t  xDevices,
uint8_t  yDevices 
)

Class Constructor - arbitrary digital interface.

Instantiate a new instance of the class. The parameters passed are used to connect the software to the hardware. Multiple instances may co-exist but they should not share the same hardware CS pin (SPI interface).

Parameters
modthe hardware module being used, one of the MD_MAX72XX::moduleType_t values
dataPinoutput on the Arduino where data gets shifted out.
clkPinoutput for the clock signal.
csPinoutput for selecting the device.
xDevicesnumber of LED matrix modules for the width of the panel.
yDevicesnumber of LED matrix modules for the height of the panel.

◆ MD_MAXPanel() [2/3]

MD_MAXPanel::MD_MAXPanel ( MD_MAX72XX::moduleType_t  mod,
uint8_t  csPin,
uint8_t  xDevices,
uint8_t  yDevices 
)

Class Constructor - SPI hardware interface.

Instantiate a new instance of the class. The parameters passed are used to connect the software to the hardware. Multiple instances may co-exist but they should not share the same hardware CS pin (SPI interface). The dataPin and the clockPin are defined by the Arduino hardware definition (SPI MOSI and SCK signals).

Parameters
modthe hardware module being used, one of the MD_MAX72XX::moduleType_t values
csPinoutput for selecting the device.
xDevicesnumber of LED matrix modules for the width of the panel.
yDevicesnumber of LED matrix modules for the height of the panel.

◆ MD_MAXPanel() [3/3]

MD_MAXPanel::MD_MAXPanel ( MD_MAX72XX *  D,
uint8_t  xDevices,
uint8_t  yDevices 
)

Class Constructor - Existing MD_MAX72XX object.

Instantiate a new instance of the class. The parameters passed are used to connect the software to the hardware. The MD_MAX72X object has been created outside this object and it is up to the programmer to ensure that the correct parameters are used when this object is created.

Parameters
Dpointer to the existing MD_MAX72XX object.
xDevicesnumber of LED matrix modules for the width of the panel.
yDevicesnumber of LED matrix modules for the height of the panel.

◆ ~MD_MAXPanel()

MD_MAXPanel::~MD_MAXPanel ( void  )

Class Destructor.

Released allocated memory and does the necessary to clean up once the object is no longer required.

Member Function Documentation

◆ begin()

void MD_MAXPanel::begin ( void  )

Initialize the object.

Initialize the object data. This needs to be called during setup() to initialize new data for the class that cannot be done during the object creation.

◆ clear() [1/2]

void MD_MAXPanel::clear ( void  )

Clear all the display data on all the display devices.

Returns
No return value.

◆ clear() [2/2]

void MD_MAXPanel::clear ( uint16_t  x1,
uint16_t  y1,
uint16_t  x2,
uint16_t  y2,
bool  state = false 
)

Clear the specified display area.

Clear the rectangular area specified by the coordinates by setting the pixels to the state specified (default is off).

Parameters
x1the upper left x coordinate of the window
y1the upper left y coordinate of the window
x2the lower right x coordinate of the window
y2the upper lower right y coordinate of the window
statetrue - switch pixels on; false - switch pixels off. If omitted, default to false.
Returns
No return value.

◆ drawCircle()

bool MD_MAXPanel::drawCircle ( uint16_t  xc,
uint16_t  yc,
uint16_t  r,
bool  state = true 
)

Draw a circle given center and radius

Draw a circle given center and radius. The LEDs will be turned on or off depending on the value supplied. The coordinates will be dereferenced into the device and column within the device, allowing the LEDs to be treated as a continuous pixel field.

Parameters
xcx coordinate for the center point [0..getXMax()].
ycy coordinate for the center point [0..getYMax()].
rradius of the circle.
statetrue - switch on; false - switch off. If omitted, default to true.
Returns
false if any point is drawn outside the display, true otherwise.

◆ drawFillCircle()

bool MD_MAXPanel::drawFillCircle ( uint16_t  xc,
uint16_t  yc,
uint16_t  r,
bool  state = true 
)

Draw a filled circle given center and radius

Draw a circle given center and radius. The LEDs for the border and fill will be turned on or off depending on the value supplied. The coordinates will be dereferenced into the device and column within the device, allowing the LEDs to be treated as a continuous pixel field.

Parameters
xcx coordinate for the center point [0..getXMax()].
ycy coordinate for the center point [0..getYMax()].
rradius of the circle.
statetrue - switch on; false - switch off. If omitted, default to true.
Returns
false if any point is drawn outside the display, true otherwise.

◆ drawFillRectangle()

bool MD_MAXPanel::drawFillRectangle ( uint16_t  x1,
uint16_t  y1,
uint16_t  x2,
uint16_t  y2,
bool  state = true 
)

Draw a filled rectangle given two diagonal vertices

Draw a filled rectangle given the points across the diagonal. The LEDs inside and on the border will be turned on or off depending on the value supplied. The coordinates will be dereferenced into the device and column within the device, allowing the LEDs to be treated as a continuous pixel field.

Parameters
x1starting x coordinate for the point [0..getXMax()].
y1starting y coordinate for the point [0..getYMax()].
x2ending x coordinate for the point [0..getXMax()].
y2ending y coordinate for the point [0..getYMax()].
statetrue - switch on; false - switch off. If omitted, default to true.
Returns
false if any point is drawn outside the display, true otherwise.

◆ drawFillTriangle()

bool MD_MAXPanel::drawFillTriangle ( uint16_t  x1,
uint16_t  y1,
uint16_t  x2,
uint16_t  y2,
uint16_t  x3,
uint16_t  y3,
bool  state = true 
)

Draw a filled triangle given 3 vertices

Draw a filled triangle given the all the corner points. The LED for the border and fill will be turned on or off depending on the value supplied. The coordinates will be dereferenced into the device and column within the device, allowing the LEDs to be treated as a continuous pixel field.

Parameters
x1first x coordinate for the point [0..getXMax()].
y1first y coordinate for the point [0..getYMax()].
x2second x coordinate for the point [0..getXMax()].
y2second y coordinate for the point [0..getYMax()].
x3third x coordinate for the point [0..getXMax()].
y3third y coordinate for the point [0..getYMax()].
statetrue - switch on; false - switch off. If omitted, default to true.
Returns
false if any point is drawn outside the display, true otherwise.

◆ drawHLine()

bool MD_MAXPanel::drawHLine ( uint16_t  y,
uint16_t  x1,
uint16_t  x2,
bool  state = true 
)

Draw a horizontal line between two points on the display

Draw a horizontal line between the specified points. The LED will be turned on or off depending on the value supplied. The column number will be dereferenced into the device and column within the device, allowing the LEDs to be treated as a continuous pixel field.

Parameters
yy coordinate for the line [0..getYMax()].
x1starting x coordinate for the point [0..getXMax()].
x2ending x coordinate for the point [0..getXMax()].
statetrue - switch on; false - switch off. If omitted, default to true.
Returns
false if any point is drawn outside the display, true otherwise.

◆ drawLine()

bool MD_MAXPanel::drawLine ( uint16_t  x1,
uint16_t  y1,
uint16_t  x2,
uint16_t  y2,
bool  state = true 
)

Draw an arbitrary line between two points on the display

Draw a line between the specified points using Bresenham's algorithm. The LED will be turned on or off depending on the value supplied. The column number will be dereferenced into the device and column within the device, allowing the LEDs to be treated as a continuous pixel field.

Parameters
x1starting x coordinate for the point [0..getXMax()].
y1starting y coordinate for the point [0..getYMax()].
x2ending x coordinate for the point [0..getXMax()].
y2ending y coordinate for the point [0..getYMax()].
statetrue - switch on; false - switch off. If omitted, default to true.
Returns
false if any point is drawn outside the display, true otherwise.

◆ drawQuadrilateral()

bool MD_MAXPanel::drawQuadrilateral ( uint16_t  x1,
uint16_t  y1,
uint16_t  x2,
uint16_t  y2,
uint16_t  x3,
uint16_t  y3,
uint16_t  x4,
uint16_t  y4,
bool  state = true 
)

Draw a quadrilateral given 4 vertices

Draw a quadrilateral given the all the corner points. The LED will be turned on or off depending on the value supplied. The coordinates will be dereferenced into the device and column within the device, allowing the LEDs to be treated as a continuous pixel field.

Parameters
x1first x coordinate for the point [0..getXMax()].
y1first y coordinate for the point [0..getYMax()].
x2second x coordinate for the point [0..getXMax()].
y2second y coordinate for the point [0..getYMax()].
x3third x coordinate for the point [0..getXMax()].
y3third y coordinate for the point [0..getYMax()].
x4fourth x coordinate for the point [0..getXMax()].
y4fourth y coordinate for the point [0..getYMax()].
statetrue - switch on; false - switch off. If omitted, default to true.
Returns
false if any point is drawn outside the display, true otherwise.

◆ drawRectangle()

bool MD_MAXPanel::drawRectangle ( uint16_t  x1,
uint16_t  y1,
uint16_t  x2,
uint16_t  y2,
bool  state = true 
)

Draw a rectangle given two diagonal vertices

Draw a rectangle given the points across the diagonal. The LED will be turned on or off depending on the value supplied. The coordinates will be dereferenced into the device and column within the device, allowing the LEDs to be treated as a continuous pixel field.

Parameters
x1starting x coordinate for the point [0..getXMax()].
y1starting y coordinate for the point [0..getYMax()].
x2ending x coordinate for the point [0..getXMax()].
y2ending y coordinate for the point [0..getYMax()].
statetrue - switch on; false - switch off. If omitted, default to true.
Returns
false if any point is drawn outside the display, true otherwise.

◆ drawText()

uint16_t MD_MAXPanel::drawText ( uint16_t  x,
uint16_t  y,
const char *  psz,
rotation_t  rot = ROT_0,
bool  state = true 
)

Draw text on the display.

Get the specified of height of the current font in pixels. All the characters of the font will fit with this height.

Parameters
xthe x coordinate for the top left corner of the first character.
ythe Y coordinate for the top left corner of the first character.
pszthe text to be displayed as a nul terminated character array.
rotthe required rotation orientation for the text as described in textRotation_t. Default is ROT_0.
statetrue - switch on; false - switch off. If omitted, default to true.
Returns
the length of the text in pixels.

◆ drawTriangle()

bool MD_MAXPanel::drawTriangle ( uint16_t  x1,
uint16_t  y1,
uint16_t  x2,
uint16_t  y2,
uint16_t  x3,
uint16_t  y3,
bool  state = true 
)

Draw a triangle given 3 vertices

Draw a triangle given the all the corner points. The LED will be turned on or off depending on the value supplied. The coordinates will be dereferenced into the device and column within the device, allowing the LEDs to be treated as a continuous pixel field.

Parameters
x1first x coordinate for the point [0..getXMax()].
y1first y coordinate for the point [0..getYMax()].
x2second x coordinate for the point [0..getXMax()].
y2second y coordinate for the point [0..getYMax()].
x3third x coordinate for the point [0..getXMax()].
y3third y coordinate for the point [0..getYMax()].
statetrue - switch on; false - switch off. If omitted, default to true.
Returns
false if any point is drawn outside the display, true otherwise.

◆ drawVLine()

bool MD_MAXPanel::drawVLine ( uint16_t  x,
uint16_t  y1,
uint16_t  y2,
bool  state = true 
)

Draw a vertical line between two points on the display

Draw a horizontal line between the specified points. The LED will be turned on or off depending on the value supplied. The column number will be dereferenced into the device and column within the device, allowing the LEDs to be treated as a continuous pixel field.

Parameters
xx coordinate for the line [0..getXMax()].
y1starting y coordinate for the point [0..getYMax()].
y2ending y coordinate for the point [0..getYMax()].
statetrue - switch on; false - switch off. If omitted, default to true.
Returns
false if any point is drawn outside the display, true otherwise.

◆ getCharSpacing()

uint8_t MD_MAXPanel::getCharSpacing ( void  )

Get the spacing between characters.

Get number of pixel columns between each character in a displayed text.

Returns
the spacing between characters.

◆ getFontHeight()

uint16_t MD_MAXPanel::getFontHeight ( void  )

Get the height of the current font in pixels.

Get the specified of height of the current font in pixels. All the characters of the font will fit with this height.

Returns
the height in pixels.

◆ getGraphicObject()

MD_MAX72XX* MD_MAXPanel::getGraphicObject ( void  )

Get a pointer to the instantiated graphics object.

Provides a pointer to the MD_MAX72XX object to allow access to the display graphics functions.

Returns
Pointer to the MD_MAX72xx object used by the library.

◆ getPoint()

bool MD_MAXPanel::getPoint ( uint16_t  x,
uint16_t  y 
)

Get the status of a single LED, addressed as a pixel.

The method will get the status of a specific LED element based on its coordinate position. The column number is dereferenced into the device and column within the device, allowing the LEDs to be treated as a planar pixel field.

Parameters
xx coordinate [0..getXMax()].
yy coordinate [0..getYMax()].
Returns
true if LED is on, false if off or parameter errors.

◆ getRotation()

rotation_t MD_MAXPanel::getRotation ( void  )

Get the rotation status of the display

Returns
rotation_t value for the current rotation (ROT_0 or ROT_90)

◆ getTextWidth()

uint16_t MD_MAXPanel::getTextWidth ( const char *  psz)

Get the length of a text string in pixels.

Get the length of a string in pixels. The text is a nul terminated characters array. The returned length will include all inter-character Set number of pixel columns between each character in a displayed text.

Parameters
pszthe text string as a nul terminated character array.
Returns
the length in pixels.

◆ getXMax()

uint16_t MD_MAXPanel::getXMax ( void  )

Gets the maximum X coordinate.

Depends on the rotation status of the display.

Returns
uint8_t the maximum X coordinate.

◆ getYMax()

uint16_t MD_MAXPanel::getYMax ( void  )

Gets the maximum Y coordinate.

Depends on the rotation status of the display.

Returns
uint16_t representing the number of columns.

◆ setCharSpacing()

void MD_MAXPanel::setCharSpacing ( uint8_t  spacing)

Set the spacing between characters.

Set number of pixel columns between each character in a displayed text.

Parameters
spacingthe spacing between characters.
Returns
No return value.

◆ setFont()

void MD_MAXPanel::setFont ( MD_MAX72XX::fontType_t *  fontDef)

Set the display font.

Set the display font to a user defined font table. This can be created using the MD_MAX72xx font builder (refer to documentation for the tool and the MD_MAX72xx library). Passing nullptr resets to the library default font.

Parameters
fontDefPointer to the font definition to be used.
Returns
No return value.

◆ setIntensity()

void MD_MAXPanel::setIntensity ( uint8_t  intensity)

Set the display intensity.

Set the intensity (brightness) of the display.

Parameters
intensitythe intensity to set the display (0-15).
Returns
No return value.

◆ setPoint()

bool MD_MAXPanel::setPoint ( uint16_t  x,
uint16_t  y,
bool  state = true 
)

Set the status of a single LED, addressed as a pixel.

The method will set the value of a specific LED element based on its coordinate position. The LED will be turned on or off depending on the value supplied. The column number is dereferenced into the device and column within the device, allowing the LEDs to be treated as a planar pixel field.

Parameters
xx coordinate [0..getXMax()].
yy coordinate [0..getYMax()].
statetrue - switch on; false - switch off. If omitted, default to true.
Returns
false if parameter errors, true otherwise.

◆ setRotation()

void MD_MAXPanel::setRotation ( rotation_t  r)

Set rotation status of the display

Set the display to be rotated or not. ROT_90 and ROT_270 rotate the display by 90 degrees in the same direction. ROT_O and ROT_180 are an unrotated display. The default is ROT_O (unrotated).

Parameters
rrotation_t value for the current rotation (ROT_0 or ROT_90);
Returns
No return value

◆ update() [1/2]

void MD_MAXPanel::update ( bool  state)

Turn auto display updates on or off.

Turn auto updates on and off, as required. When auto updates are turned OFF the display will not update after each operation. Display updates can be forced at any time using using a call to update() with no parameters.

Parameters
statetrue to enable update, false to suspend updates.
Returns
No return value.

◆ update() [2/2]

void MD_MAXPanel::update ( )

Force a display update.

Force a display update of any changes since the last update. This overrides the current setting for display updates.

Returns
No return value.

The documentation for this class was generated from the following files: