tm1637

package
v3.6.4+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package tm1637 controls a TM1637 device over GPIO pins.

More details

See https://periph.io/device/tm1637/ for more details about the device.

Datasheet

http://olimex.cl/website_MCI/static/documents/Datasheet_TM1637.pdf

Example
package main

import (
	"log"

	"periph.io/x/periph/conn/gpio/gpioreg"
	"periph.io/x/periph/devices/tm1637"
	"periph.io/x/periph/host"
)

func main() {
	// Make sure periph is initialized.
	if _, err := host.Init(); err != nil {
		log.Fatal(err)
	}

	clk := gpioreg.ByName("GPIO6")
	data := gpioreg.ByName("GPIO12")
	if clk == nil || data == nil {
		log.Fatal("Failed to find pins")
	}
	dev, err := tm1637.New(clk, data)
	if err != nil {
		log.Fatalf("failed to initialize tm1637: %v", err)
	}
	if err := dev.SetBrightness(tm1637.Brightness10); err != nil {
		log.Fatalf("failed to set brightness on tm1637: %v", err)
	}
	if _, err := dev.Write(tm1637.Clock(12, 00, true)); err != nil {
		log.Fatalf("failed to write to tm1637: %v", err)
	}
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clock

func Clock(hour, minute int, showDots bool) []byte

Clock converts time to a slice of bytes as segments.

func Digits

func Digits(n ...int) []byte

Digits converts hex numbers to a slice of bytes as segments.

Numbers outside the range [0, 15] are displayed as blank. Use -1 to mark it as blank.

Types

type Brightness

type Brightness uint8

Brightness defines the screen brightness as controlled by the internal PWM.

const (
	Off          Brightness = 0x80 // Completely off.
	Brightness1  Brightness = 0x88 // 1/16 PWM
	Brightness2  Brightness = 0x89 // 2/16 PWM
	Brightness4  Brightness = 0x8A // 4/16 PWM
	Brightness10 Brightness = 0x8B // 10/16 PWM
	Brightness11 Brightness = 0x8C // 11/16 PWM
	Brightness12 Brightness = 0x8D // 12/16 PWM
	Brightness13 Brightness = 0x8E // 13/16 PWM
	Brightness14 Brightness = 0x8F // 14/16 PWM
)

Valid brightness values.

type Dev

type Dev struct {
	// contains filtered or unexported fields
}

Dev represents an handle to a tm1637.

func New

func New(clk gpio.PinOut, data gpio.PinIO) (*Dev, error)

New returns an object that communicates over two pins to a TM1637.

func (*Dev) Halt

func (d *Dev) Halt() error

Halt turns the display off.

func (*Dev) SetBrightness

func (d *Dev) SetBrightness(b Brightness) error

SetBrightness changes the brightness and/or turns the display on and off.

func (*Dev) String

func (d *Dev) String() string

func (*Dev) Write

func (d *Dev) Write(seg []byte) (int, error)

Write writes raw segments, while implementing io.Writer.

P can be a dot or ':' following a digit. Otherwise it is likely disconnected. Each byte is encoded as PGFEDCBA.

 -A-
F   B
 -G-
E   C
 -D-   P

Jump to

Keyboard shortcuts

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