max7219

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2018 License: MIT Imports: 9 Imported by: 3

README

MAX7219 driver and 8x8 LED matrix display

Build Status Go Report Card GoDoc MIT License

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: image image

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

View Source
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
)
View Source
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 NewDevice

func NewDevice(cascaded int) *Device

func (*Device) Brightness

func (this *Device) Brightness(intensity byte) error

func (*Device) Clear

func (this *Device) Clear(cascadeId int, redraw bool) error

func (*Device) ClearAll

func (this *Device) ClearAll(redraw bool) error

func (*Device) Close

func (this *Device) Close()

func (*Device) Command

func (this *Device) Command(reg Max7219Reg, value byte) error

func (*Device) Flush

func (this *Device) Flush() error

func (*Device) GetCascadeCount

func (this *Device) GetCascadeCount() int

func (*Device) GetLedLineCount

func (this *Device) GetLedLineCount() int

func (*Device) Open

func (this *Device) Open(spibus int, spidevice int, brightness byte) error

func (*Device) ScrollLeft

func (this *Device) ScrollLeft(redraw bool) error

func (*Device) ScrollRight

func (this *Device) ScrollRight(redraw bool) error

func (*Device) SetBufferLine

func (this *Device) SetBufferLine(cascadeId int,
	position int, value byte, redraw bool) error

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 NewMatrix

func NewMatrix(cascaded int) *Matrix

func (*Matrix) Close

func (this *Matrix) Close()

func (*Matrix) Open

func (this *Matrix) Open(spibus int, spidevice int, brightness byte) error

func (*Matrix) OutputAsciiCode

func (this *Matrix) OutputAsciiCode(cascadeId int, font Font,
	asciiCode int, redraw bool) error

Output ascii code to the led matrix.

func (*Matrix) OutputChar

func (this *Matrix) OutputChar(cascadeId int, font Font,
	char rune, redraw bool) error

Output unicode char to the led matrix. Unicode char transforms to ascii code based on information taken from font.GetCodePage() call.

func (*Matrix) SlideMessage

func (this *Matrix) SlideMessage(text string, font Font,
	condensePattern bool, pixelDelay time.Duration) error

Show message sliding it by led matrix from the right to left.

type Max7219Reg

type Max7219Reg byte

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL