Files
hh/hhio/relay.go
2022-09-24 17:20:10 -07:00

33 lines
361 B
Go

package hhio
import "github.com/stianeikeland/go-rpio/v4"
type Relay struct {
pin rpio.Pin
on bool
}
func NewRelay(pin int) *Relay {
r := &Relay{
pin: rpio.Pin(pin),
}
r.pin.Output()
return r
}
func (r *Relay) On() {
r.pin.High()
r.on = true
}
func (r *Relay) Off() {
r.pin.Low()
r.on = false
}
func (r *Relay) IsOn() bool {
return r.on
}