sn3218

package
v3.6.7+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2020 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package sn3218 controls a SN3218 LED driver with 18 LEDs over an i2c bus.

Datasheet

http://www.si-en.com/uploadpdf/s2011517171720.pdf

Example
package main

import (
	"log"
	"time"

	"periph.io/x/periph/conn/i2c/i2creg"
	"periph.io/x/periph/experimental/devices/sn3218"
	"periph.io/x/periph/host"
)

func main() {
	if _, err := host.Init(); err != nil {
		log.Fatal(err)
	}

	b, err := i2creg.Open("")
	if err != nil {
		log.Fatal(err)
	}
	defer b.Close()

	d, err := sn3218.New(b)
	if err != nil {
		log.Fatal(err)
	}
	defer d.Halt()

	// By default, the device is disabled and brightness is 0 for all LEDs
	// So let's set the brightness to a low value and enable the device to
	// get started
	d.BrightnessAll(1)
	d.Sleep()

	// Switch LED 7 on
	if err := d.Switch(7, true); err != nil {
		log.Fatal("Error while switching LED", err)
	}

	time.Sleep(1000 * time.Millisecond)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dev

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

Dev is a handler to sn3218 controller.

func New

func New(bus i2c.Bus) (*Dev, error)

New returns a handle to a SN3218 LED driver.

func (*Dev) Brightness

func (d *Dev) Brightness(channel int, value byte) error

Brightness sets the brightness of led (0..17) to value (0..255).

func (*Dev) BrightnessAll

func (d *Dev) BrightnessAll(value byte) error

BrightnessAll sets the brightness of all channels to the value (0..255).

func (*Dev) GetState

func (d *Dev) GetState(channel int) (bool, byte, error)

GetState returns the state (on/off) and the brightness (0..255) of the Channel 0..17.

func (*Dev) Halt

func (d *Dev) Halt() error

Halt resets the registers and switches the driver off.

func (*Dev) Sleep

func (d *Dev) Sleep() error

Sleep sends SN3218 to sleep mode while keeping the states in the registers.

func (*Dev) Switch

func (d *Dev) Switch(channel int, state bool) error

Switch switched the channel (0..18) to state (on/off).

func (*Dev) SwitchAll

func (d *Dev) SwitchAll(state bool) error

SwitchAll switches all channels according to the state (on/off).

func (*Dev) WakeUp

func (d *Dev) WakeUp() error

WakeUp returns from sleep mode and switches the channels according to the states in the register of SN3218.

Jump to

Keyboard shortcuts

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