Remarks
MAX7219 | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
The MAX7219 is an LED display driver capable of driving 64 outputs. As well, the MAX7219 contains an 2-wire data bus allowing multiple MAX7219 chip to be connected together and controlled by a single I2C interface.
Although the MAX7219 can be used as a general purpose IO expander, it almost exclusively used to drive either 2-dimensional LED arrays (commonly 8x8) or an array of multi-segment displays (commonly 8 7-segment displays). The MAX7219 contains specific logic to display pre-configured characters when driving 7 segment displays, specifically: 0-9, E, H, L, P and -.
As it's most commonly used to as a display controller, you'll find it in the Meadow.Foundation.Displays namespace.
Code Example
public class MeadowApp : App<F7Micro, MeadowApp>
{
Max7219 display;
public MeadowApp()
{
Init();
while(true)
{
TestDigitalMode();
TestCharacterMode();
CharacterDemo();
}
}
void CharacterDemo()
{
display.SetMode(true);
display.ClearAll();
for (int i = 0; i < 8; i++)
{
display.SetCharacter(Max7219.CharacterType.Blank, i);
}
for (int i = 980; i < 999; i++)
{
display.SetNumber(i);
display.Show();
}
display.SetCharacter(Max7219.CharacterType.Hyphen, 0);
display.SetCharacter(Max7219.CharacterType.Hyphen, 1);
display.SetCharacter(Max7219.CharacterType.P, 2);
display.SetCharacter(Max7219.CharacterType.L, 3);
display.SetCharacter(Max7219.CharacterType.E, 4);
display.SetCharacter(Max7219.CharacterType.H, 5);
display.SetCharacter(Max7219.CharacterType.Hyphen, 6);
display.SetCharacter(Max7219.CharacterType.Hyphen, 7);
display.Show();
Thread.Sleep(1000);
}
void TestCharacterMode()
{
display.SetMode(true);
for (int i = 0; i < (int)Max7219.CharacterType.count; i++)
{
for (int digit = 0; digit < 8; digit++)
{
display.SetCharacter((Max7219.CharacterType)i, digit, i%2 == 0);
}
display.Show();
Console.WriteLine(((Max7219.CharacterType)i).ToString());
}
}
void TestDigitalMode()
{
display.SetMode(false);
for (byte i = 0; i < 64; i++)
{
for(int d = 0; d < 8; d++)
{
display.SetDigit(i, d);
}
display.Show();
}
}
public void Init()
{
Console.WriteLine("Init...");
display = new Max7219(Device, Device.CreateSpiBus(), Device.Pins.D02, 1, true);
}
}
Sample projects available on GitHub
Characteristic | Locus |
---|---|
Inheritance | System.Object DisplayBase > Max7219 |
Inherited Members | DisplayBase.IgnoreOutOfBoundsPixels |
Namespace | Meadow.Foundation.Displays |
Assembly | Max7219.dll |
Syntax
public class Max7219 : DisplayBase
Constructors
Max7219(IIODevice, ISpiBus, IPin, Int32, Max7219.Max7219Type)
Declaration
public Max7219(IIODevice device, ISpiBus spiBus, IPin csPin, int deviceCount = 1, Max7219.Max7219Type maxMode = Max7219.Max7219Type.Display)
Parameters
Type | Name | Description |
---|---|---|
IIODevice | device | |
ISpiBus | spiBus | |
IPin | csPin | |
System.Int32 | deviceCount | |
Max7219.Max7219Type | maxMode |
Max7219(IIODevice, ISpiBus, IPin, Int32, Int32, Max7219.Max7219Type)
Creates a Max7219 Device given a
Declaration
public Max7219(IIODevice device, ISpiBus spiBus, IPin csPin, int deviceRows = 1, int deviceColumns = 1, Max7219.Max7219Type maxMode = Max7219.Max7219Type.Display)
Parameters
Type | Name | Description |
---|---|---|
IIODevice | device | |
ISpiBus | spiBus | |
IPin | csPin | |
System.Int32 | deviceRows | |
System.Int32 | deviceColumns | |
Max7219.Max7219Type | maxMode |
Max7219(ISpiBus, IDigitalOutputPort, Int32, Max7219.Max7219Type)
Declaration
public Max7219(ISpiBus spiBus, IDigitalOutputPort csPort, int deviceCount = 1, Max7219.Max7219Type maxMode = Max7219.Max7219Type.Display)
Parameters
Type | Name | Description |
---|---|---|
ISpiBus | spiBus | |
IDigitalOutputPort | csPort | |
System.Int32 | deviceCount | |
Max7219.Max7219Type | maxMode |
Max7219(ISpiBus, IDigitalOutputPort, Int32, Int32, Max7219.Max7219Type)
Declaration
public Max7219(ISpiBus spiBus, IDigitalOutputPort csPort, int deviceRows, int deviceColumns, Max7219.Max7219Type maxMode = Max7219.Max7219Type.Display)
Parameters
Type | Name | Description |
---|---|---|
ISpiBus | spiBus | |
IDigitalOutputPort | csPort | |
System.Int32 | deviceRows | |
System.Int32 | deviceColumns | |
Max7219.Max7219Type | maxMode |
Fields
NumDigits
Number of digits Register per Module
Declaration
public const int NumDigits = 8
Field Value
Type | Description |
---|---|
System.Int32 |
Properties
ColorMode
Declaration
public override DisplayBase.DisplayColorMode ColorMode { get; }
Property Value
Type | Description |
---|---|
DisplayBase.DisplayColorMode |
Overrides
DeviceColumns
Declaration
public int DeviceColumns { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
DeviceCount
Number of cascaded devices
Declaration
public int DeviceCount { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
DeviceRows
Declaration
public int DeviceRows { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Height
Declaration
public override uint Height { get; }
Property Value
Type | Description |
---|---|
System.UInt32 |
Overrides
Length
Gets the total number of digits (cascaded devices * num digits)
Declaration
public int Length { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
SpiClockFrequency
MAX7219 Spi Clock Frequency
Declaration
public static int SpiClockFrequency { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Width
Declaration
public override uint Width { get; }
Property Value
Type | Description |
---|---|
System.UInt32 |
Overrides
Methods
Clear(Boolean)
Clears the buffer from the given start to end and flushes
Declaration
public override void Clear(bool updateDisplay = false)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | updateDisplay |
Overrides
Clear(Int32, Int32)
Clears the buffer from the given start to end (exclusive) and flushes
Declaration
public void Clear(int start, int end)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | start | |
System.Int32 | end |
DrawPixel(Int32, Int32)
Declaration
public override void DrawPixel(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | |
System.Int32 | y |
Overrides
DrawPixel(Int32, Int32, Color)
Declaration
public override void DrawPixel(int x, int y, Color color)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | |
System.Int32 | y | |
Color | color |
Overrides
DrawPixel(Int32, Int32, Boolean)
Declaration
public override void DrawPixel(int x, int y, bool colored)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | |
System.Int32 | y | |
System.Boolean | colored |
Overrides
GetCharacter(Int32, Int32)
Declaration
public Max7219.CharacterType GetCharacter(int digit, int deviceId = 0)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | digit | |
System.Int32 | deviceId |
Returns
Type | Description |
---|---|
Max7219.CharacterType |
GetDigit(Int32, Int32)
Declaration
public byte GetDigit(int digit, int deviceId = 0)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | digit | |
System.Int32 | deviceId |
Returns
Type | Description |
---|---|
System.Byte |
InvertPixel(Int32, Int32)
Declaration
public override void InvertPixel(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | |
System.Int32 | y |
Overrides
SetBrightness(Int32)
Sets the brightness of all cascaded devices to the same intensity level.
Declaration
public void SetBrightness(int intensity)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | intensity | intensity level ranging from 0..15. |
SetCharacter(Max7219.CharacterType, Int32, Boolean, Int32)
Declaration
public void SetCharacter(Max7219.CharacterType character, int digit, bool showDecimal = false, int deviceId = 0)
Parameters
Type | Name | Description |
---|---|---|
Max7219.CharacterType | character | |
System.Int32 | digit | |
System.Boolean | showDecimal | |
System.Int32 | deviceId |
SetDigit(Byte, Int32, Int32)
Declaration
public void SetDigit(byte value, int digit, int deviceId = 0)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | value | |
System.Int32 | digit | |
System.Int32 | deviceId |
SetMode(Max7219.Max7219Type)
Declaration
public void SetMode(Max7219.Max7219Type maxMode)
Parameters
Type | Name | Description |
---|---|---|
Max7219.Max7219Type | maxMode |
SetNumber(Int32, Int32)
Declaration
public void SetNumber(int value, int deviceId = 0)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | value | |
System.Int32 | deviceId |
SetPenColor(Color)
Declaration
public override void SetPenColor(Color pen)
Parameters
Type | Name | Description |
---|---|---|
Color | pen |
Overrides
Show()
Writes all the Values to the devices.
Declaration
public override void Show()
Overrides
TestDisplay(Int32)
Declaration
public void TestDisplay(int timeInMs = 1000)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | timeInMs |
WriteBuffer(Byte[,])
Writes a two dimensional buffer containing all the values to the devices.
Declaration
public void WriteBuffer(byte[, ] buffer)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[,] | buffer |