README
¶
MAX7219 driver and 8x8 LED matrix display
This library written in Go programming language to output a text messages to 8x8 LED matrix display (pdf reference) via MAX7219 driver chip (pdf reference) from Raspberry PI or counterparts:
Compatibility
Tested on Raspberry PI 1 (model B) and Banana PI (model M1).
Golang usage
func main() {
// Create new LED matrix with number of cascaded devices is equal to 1
mtx := max7219.NewMatrix(1)
// Open SPI device with spibus and spidev parameters equal to 0 and 0.
// Set LED matrix brightness is equal to 7
err := mtx.Open(0, 0, 7)
if err != nil {
log.Fatal(err)
}
defer mtx.Close()
// Output text message to LED matrix
mtx.SlideMessage("Hello world!!! Hey Beavis, let's rock!",
max7219.FontCP437, true, 50*time.Millisecond)
// Wait 1 sec, then continue output new text
time.Sleep(1 * time.Second)
// Output national text (russian in example) to LED matrix
mtx.SlideMessage("Привет мир!!! Шарик, ты - балбес!!!",
max7219.FontZXSpectrumRus, true, 50*time.Millisecond)
}
Getting help
GoDoc documentation
Installation
$ go get -u github.com/d2r2/go-max7219
Quick Start
To output a single letter to LED matrix by specifing ascii code use OutputAsciiCode call:
// Output a sequence of ascii codes in a loop
font = max7219.FontCP437
for i := 0; i <= len(font.GetLetterPatterns()); i++ {
mtx.OutputAsciiCode(0, font, i, true)
time.Sleep(500 * time.Millisecond)
}
To output a single national letter either unicode letter (rune) to LED matrix use OutputChar call:
// Output non-latin national letter (russian for example).
// You must be sure, that your national letter will match code page of the font used.
mtx.OutputChar(0, max7219.FontZXSpectrumRus, 'Я', true)
This functionality works not only with Raspberry PI, but with counterparts as well (tested with Raspberry PI and Banana PI). It will works with any Raspberry PI clone, which support Kernel SPI bus, but you should in advance make SPI bus device available in /dev/ list.
More national fonts
If you want to add your national fonts you could use linux shell scripts in folder "extract_fonts" to convert font image to bit patterns. Let me know if you need assistance in this.
Credits
This project is mainly a fork of respective functionality originally written by Richard Hull in python: https://github.com/rm-hull/max7219. Nevertheless it differs in some parts: refuse some functionality (works only with matrix led), include extra functionality (extra fonts, support of national languages).
Contact
Please use Github issue tracker for filing bugs or feature requests.
License
Go-max7219 is licensed under MIT License.
Documentation
¶
Index ¶
- Constants
- type Device
- func (this *Device) Brightness(intensity byte) error
- func (this *Device) Clear(cascadeId int, redraw bool) error
- func (this *Device) ClearAll(redraw bool) error
- func (this *Device) Close()
- func (this *Device) Command(reg Max7219Reg, value byte) error
- func (this *Device) Flush() error
- func (this *Device) GetCascadeCount() int
- func (this *Device) GetLedLineCount() int
- func (this *Device) Open(spibus int, spidevice int, brightness byte) error
- func (this *Device) ScrollLeft(redraw bool) error
- func (this *Device) ScrollRight(redraw bool) error
- func (this *Device) SetBufferLine(cascadeId int, position int, value byte, redraw bool) error
- type Font
- type Matrix
- func (this *Matrix) Close()
- func (this *Matrix) Open(spibus int, spidevice int, brightness byte) error
- func (this *Matrix) OutputAsciiCode(cascadeId int, font Font, asciiCode int, redraw bool) error
- func (this *Matrix) OutputChar(cascadeId int, font Font, char rune, redraw bool) error
- func (this *Matrix) SlideMessage(text string, font Font, condensePattern bool, pixelDelay time.Duration) error
- type Max7219Reg
Constants ¶
const ( MAX7219_REG_NOOP Max7219Reg = 0 MAX7219_REG_DIGIT0 = iota MAX7219_REG_DIGIT1 MAX7219_REG_DIGIT2 MAX7219_REG_DIGIT3 MAX7219_REG_DIGIT4 MAX7219_REG_DIGIT5 MAX7219_REG_DIGIT6 MAX7219_REG_DIGIT7 MAX7219_REG_DECODEMODE MAX7219_REG_INTENSITY MAX7219_REG_SCANLIMIT MAX7219_REG_SHUTDOWN MAX7219_REG_DISPLAYTEST = 0x0F MAX7219_REG_LASTDIGIT = MAX7219_REG_DIGIT7 )
const MAX7219_DIGIT_COUNT = MAX7219_REG_LASTDIGIT - MAX7219_REG_DIGIT0 + 1
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Device ¶
type Device struct {
// contains filtered or unexported fields
}
func (*Device) Brightness ¶
func (*Device) GetCascadeCount ¶
func (*Device) GetLedLineCount ¶
func (*Device) ScrollLeft ¶
func (*Device) ScrollRight ¶
type Font ¶
type Font interface { // Return font code page. // This function allow implement national font support. GetCodePage() encoding.Encoding // Return font char's bit pattern. // Font height is always equal to 8 pixel. // Font width may vary from one font // to another, but ordinary not exceed 8 pixel. GetLetterPatterns() [][]byte }
General interface of ASCII char set bit pattern for drawing on the LED matrix.
var ( FontCP437 Font = &fontCP437{} FontSinclair Font = &fontSinclair{} FontLCD Font = &fontLCD{} // FontBoldCyrillic Font = &fontBoldCyrillic{} FontTiny Font = &fontTiny{} FontMSXRus Font = &fontMSXRus{} FontZXSpectrumRus Font = &fontZXSpectrumRus{} FontVestaPK8000Rus Font = &fontVestaPK8000Rus{} )
type Matrix ¶
type Matrix struct {
Device *Device
}
func (*Matrix) OutputAsciiCode ¶
Output ascii code to the led matrix.
func (*Matrix) OutputChar ¶
Output unicode char to the led matrix. Unicode char transforms to ascii code based on information taken from font.GetCodePage() call.
type Max7219Reg ¶
type Max7219Reg byte