![]() |
MD_MAXPanel LED Matrix Panel Arduino Library
1.2
Library to control a panel of connected MAX72XX devices
|
#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) |
Core object for the MD_MAXPanel library
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. |
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).
mod | the hardware module being used, one of the MD_MAX72XX::moduleType_t values |
dataPin | output on the Arduino where data gets shifted out. |
clkPin | output for the clock signal. |
csPin | output for selecting the device. |
xDevices | number of LED matrix modules for the width of the panel. |
yDevices | number of LED matrix modules for the height of the panel. |
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).
mod | the hardware module being used, one of the MD_MAX72XX::moduleType_t values |
csPin | output for selecting the device. |
xDevices | number of LED matrix modules for the width of the panel. |
yDevices | number of LED matrix modules for the height of the panel. |
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.
D | pointer to the existing MD_MAX72XX object. |
xDevices | number of LED matrix modules for the width of the panel. |
yDevices | number of LED matrix modules for the height of the panel. |
MD_MAXPanel::~MD_MAXPanel | ( | void | ) |
Class Destructor.
Released allocated memory and does the necessary to clean up once the object is no longer required.
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.
void MD_MAXPanel::clear | ( | void | ) |
Clear all the display data on all the display devices.
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).
x1 | the upper left x coordinate of the window |
y1 | the upper left y coordinate of the window |
x2 | the lower right x coordinate of the window |
y2 | the upper lower right y coordinate of the window |
state | true - switch pixels on; false - switch pixels off. If omitted, default to false. |
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.
xc | x coordinate for the center point [0..getXMax()]. |
yc | y coordinate for the center point [0..getYMax()]. |
r | radius of the circle. |
state | true - switch on; false - switch off. If omitted, default to true. |
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.
xc | x coordinate for the center point [0..getXMax()]. |
yc | y coordinate for the center point [0..getYMax()]. |
r | radius of the circle. |
state | true - switch on; false - switch off. If omitted, default to true. |
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.
x1 | starting x coordinate for the point [0..getXMax()]. |
y1 | starting y coordinate for the point [0..getYMax()]. |
x2 | ending x coordinate for the point [0..getXMax()]. |
y2 | ending y coordinate for the point [0..getYMax()]. |
state | true - switch on; false - switch off. If omitted, default to true. |
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.
x1 | first x coordinate for the point [0..getXMax()]. |
y1 | first y coordinate for the point [0..getYMax()]. |
x2 | second x coordinate for the point [0..getXMax()]. |
y2 | second y coordinate for the point [0..getYMax()]. |
x3 | third x coordinate for the point [0..getXMax()]. |
y3 | third y coordinate for the point [0..getYMax()]. |
state | true - switch on; false - switch off. If omitted, default to true. |
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.
y | y coordinate for the line [0..getYMax()]. |
x1 | starting x coordinate for the point [0..getXMax()]. |
x2 | ending x coordinate for the point [0..getXMax()]. |
state | true - switch on; false - switch off. If omitted, default to true. |
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.
x1 | starting x coordinate for the point [0..getXMax()]. |
y1 | starting y coordinate for the point [0..getYMax()]. |
x2 | ending x coordinate for the point [0..getXMax()]. |
y2 | ending y coordinate for the point [0..getYMax()]. |
state | true - switch on; false - switch off. If omitted, default to true. |
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.
x1 | first x coordinate for the point [0..getXMax()]. |
y1 | first y coordinate for the point [0..getYMax()]. |
x2 | second x coordinate for the point [0..getXMax()]. |
y2 | second y coordinate for the point [0..getYMax()]. |
x3 | third x coordinate for the point [0..getXMax()]. |
y3 | third y coordinate for the point [0..getYMax()]. |
x4 | fourth x coordinate for the point [0..getXMax()]. |
y4 | fourth y coordinate for the point [0..getYMax()]. |
state | true - switch on; false - switch off. If omitted, default to true. |
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.
x1 | starting x coordinate for the point [0..getXMax()]. |
y1 | starting y coordinate for the point [0..getYMax()]. |
x2 | ending x coordinate for the point [0..getXMax()]. |
y2 | ending y coordinate for the point [0..getYMax()]. |
state | true - switch on; false - switch off. If omitted, default to true. |
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.
x | the x coordinate for the top left corner of the first character. |
y | the Y coordinate for the top left corner of the first character. |
psz | the text to be displayed as a nul terminated character array. |
rot | the required rotation orientation for the text as described in textRotation_t. Default is ROT_0. |
state | true - switch on; false - switch off. If omitted, default to true. |
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.
x1 | first x coordinate for the point [0..getXMax()]. |
y1 | first y coordinate for the point [0..getYMax()]. |
x2 | second x coordinate for the point [0..getXMax()]. |
y2 | second y coordinate for the point [0..getYMax()]. |
x3 | third x coordinate for the point [0..getXMax()]. |
y3 | third y coordinate for the point [0..getYMax()]. |
state | true - switch on; false - switch off. If omitted, default to true. |
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.
x | x coordinate for the line [0..getXMax()]. |
y1 | starting y coordinate for the point [0..getYMax()]. |
y2 | ending y coordinate for the point [0..getYMax()]. |
state | true - switch on; false - switch off. If omitted, default to true. |
uint8_t MD_MAXPanel::getCharSpacing | ( | void | ) |
Get the spacing between characters.
Get number of pixel columns between each character in a displayed text.
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.
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.
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.
rotation_t MD_MAXPanel::getRotation | ( | void | ) |
Get the rotation status of the display
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.
psz | the text string as a nul terminated character array. |
uint16_t MD_MAXPanel::getXMax | ( | void | ) |
Gets the maximum X coordinate.
Depends on the rotation status of the display.
uint16_t MD_MAXPanel::getYMax | ( | void | ) |
Gets the maximum Y coordinate.
Depends on the rotation status of the display.
void MD_MAXPanel::setCharSpacing | ( | uint8_t | spacing | ) |
Set the spacing between characters.
Set number of pixel columns between each character in a displayed text.
spacing | the spacing between characters. |
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.
fontDef | Pointer to the font definition to be used. |
void MD_MAXPanel::setIntensity | ( | uint8_t | intensity | ) |
Set the display intensity.
Set the intensity (brightness) of the display.
intensity | the intensity to set the display (0-15). |
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.
x | x coordinate [0..getXMax()]. |
y | y coordinate [0..getYMax()]. |
state | true - switch on; false - switch off. If omitted, default to true. |
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).
r | rotation_t value for the current rotation (ROT_0 or ROT_90); |
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.
state | true to enable update, false to suspend updates. |
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.