microdotphat

package module
v0.0.0-...-ac28d07 Latest Latest
Warning

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

Go to latest
Published: May 28, 2022 License: Apache-2.0 Imports: 5 Imported by: 1

README

microdotphat-go

A pure Go interface to the Micro Dot pHAT LED matrix display board. The API is based on that of the official microdotphat Python library, and features an automatically resized scrollable on/off pixel buffer and built-in text drawing capabilities.

See the examples/ directory for usage examples.

Status

Breaking changes to the package may occur at any time until version v1.0.0.

Known differences from the Python microdotphat package

  • The Python package clears the display at program exit by default (configurable via set_clear_on_exit); this package does not. If you want this behavior, add this code to your func main:
    defer func() {
    	microdotphat.Clear()
    	microdotphat.Show()
    }()
    
  • The Python package has three functions for scrolling the buffer (not including scroll_to). This package collapses those functions into one Scroll function.
  • The Python package has functions set_mirror and set_rotate180. This package collapses those functions into one SetMirror function (rotation is achieved by flipping both axes).

Documentation

Overview

Package microdotphat implements a pure Go interface to the Micro Dot pHAT LED matrix display board. The API is based on that of the official microdotphat Python library, and features an automatically resized scrollable on/off pixel buffer and built-in text drawing capabilities.

Passing negative coordinates to any function will cause a panic.

Index

Constants

View Source
const (
	// Width is the width of the full display in pixels.
	Width = 45

	// Height is the height of the full display in pixels.
	Height = 7
)

Variables

View Source
var (
	ErrNoConn = errors.New("I2C bus connection not open")
)

Functions

func Clear

func Clear()

Clear clears the buffer and resets its bounds and scroll state.

func Close

func Close() error

Close closes the connection to the I2C bus.

func DrawTiny

func DrawTiny(display int, s string)

DrawTiny draws tiny numbers to the buffer. Display is the zero-based index of the display to draw numbers on; s is a string containing digits (non-digit characters are discarded). This function is not designed for use with scrolled buffers.

func Fill

func Fill(lit bool)

Fill fills the buffer either lit or unlit.

func Open

func Open(name string) error

Open initializes the library, opening a connection to the I2C bus with the given name. If left blank, the default bus is used, which is usually sufficient.

func Scroll

func Scroll(dx, dy int)

Scroll scrolls the buffer.

func ScrollTo

func ScrollTo(x, y int)

ScrollTo scrolls the buffer to a specific position.

func SetBrightness

func SetBrightness(brightness float64) error

SetBrightness sets the display brightness in the range [0.0, 1.0].

func SetCol

func SetCol(x int, col byte)

SetCol sets a whole column of the buffer (only useful when not scrolling vertically). The 7 least significant bits of col correspond to each row of the column, with the least significant bit on top.

func SetDecimal

func SetDecimal(display int, lit bool)

SetDecimal sets the state of a decimal point on a zero-indexed display. Panics if the display index is out of range.

func SetMirror

func SetMirror(x, y bool)

SetMirror sets whether the display should be flipped horizontally and/or vertically. To rotate the display 180 degrees, flip both x and y.

func SetPixel

func SetPixel(x, y int, lit bool)

SetPixel sets the buffer pixel at (x,y) to lit or unlit.

func Show

func Show() error

Show outputs the buffer to the display.

func String

func String() string

String returns a string representing the expected LED display state.

func WriteChar

func WriteChar(char rune, x, y int)

WriteChar writes a single character to the buffer at the specified position. Characters not covered by the built-in font are discarded.

func WriteString

func WriteString(s string, x, y int, kern bool)

WriteString writes a string to the buffer at the specified position. If kern is true, characters will be written closely together, ideal for scrolling displays. If kern is false, characters are arranged one per display. Characters not covered by the built-in font are discarded.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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