ep0099

package
v3.7.2 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package ep0099 controls a EP-0099 Raspberry Pi HAT with 4 relays via I2C.

Datasheet https://wiki.52pi.com/index.php/DockerPi_4_Channel_Relay_SKU:_EP-0099

Example
// Initializes host to manage bus and devices
if _, err := host.Init(); err != nil {
	log.Fatal(err)
}

// Opens default bus
bus, err := i2creg.Open("")
if err != nil {
	log.Fatal(err)
}
defer bus.Close()

// Initializes device using current I2C bus and device address.
// Address should be provided as configured on the board's DIP switches.
dev, err := ep0099.New(bus, 0x10)
if err != nil {
	log.Fatal(err)
}
defer dev.Halt()

// Run device demo
for _, channel := range dev.AvailableChannels() {
	state, _ := dev.State(channel)
	log.Printf("[channel %#x] Initial state: %s", channel, state)

	dev.On(channel)
	state, _ = dev.State(channel)
	log.Printf("[channel %#x] State after .On: %s", channel, state)

	dev.Off(channel)
	state, _ = dev.State(channel)
	log.Printf("[channel %#x] State after .Off: %s", channel, state)

	time.Sleep(2 * time.Second)
}
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
}

func New

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

func (*Dev) AvailableChannels

func (d *Dev) AvailableChannels() []uint8

func (*Dev) Halt

func (d *Dev) Halt() error

func (*Dev) Off

func (d *Dev) Off(channel uint8) error

func (*Dev) On

func (d *Dev) On(channel uint8) error

func (*Dev) State

func (d *Dev) State(channel uint8) (State, error)

type State

type State byte
const (
	StateOff State = 0x00
	StateOn  State = 0xFF
)

func (State) String

func (s State) String() string

Jump to

Keyboard shortcuts

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