Files
hh/hhio/relay.go

33 lines
361 B
Go
Raw Permalink Normal View History

2022-09-24 16:35:03 -07:00
package hhio
2022-09-24 16:29:26 -07:00
import "github.com/stianeikeland/go-rpio/v4"
type Relay struct {
pin rpio.Pin
on bool
2022-09-24 16:29:26 -07:00
}
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
2022-09-24 16:29:26 -07:00
}
func (r *Relay) Off() {
r.pin.Low()
r.on = false
}
func (r *Relay) IsOn() bool {
return r.on
2022-09-24 16:29:26 -07:00
}