hybridgroup.gobot/examples/gopigo3.go

45 lines
762 B
Go
Raw Normal View History

//go:build example
2017-09-07 13:53:28 +08:00
// +build example
2017-09-07 13:53:28 +08:00
//
// Do not build by default.
package main
import (
"fmt"
"time"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/platforms/dexter/gopigo3"
"gobot.io/x/gobot/v2/platforms/raspi"
2017-09-07 13:53:28 +08:00
)
func main() {
raspiAdaptor := raspi.NewAdaptor()
gpg3 := gopigo3.NewDriver(raspiAdaptor)
2017-09-07 13:53:28 +08:00
work := func() {
on := uint8(0xFF)
gobot.Every(1000*time.Millisecond, func() {
err := gpg3.SetLED(gopigo3.LED_EYE_RIGHT, 0x00, 0x00, on)
2017-09-07 13:53:28 +08:00
if err != nil {
fmt.Println(err)
}
err = gpg3.SetLED(gopigo3.LED_EYE_LEFT, ^on, 0x00, 0x00)
2017-09-07 13:53:28 +08:00
if err != nil {
fmt.Println(err)
}
on = ^on
})
}
robot := gobot.NewRobot("gopigo3eyeleds",
[]gobot.Connection{raspiAdaptor},
[]gobot.Device{gpg3},
2017-09-07 13:53:28 +08:00
work,
)
robot.Start()
}