hybridgroup.gobot/examples/raspi_blink.go

40 lines
569 B
Go
Raw Permalink Normal View History

//go:build example
// +build example
//
// Do not build by default.
2014-11-05 09:14:36 +08:00
package main
import (
"fmt"
2014-11-05 09:14:36 +08:00
"time"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/drivers/gpio"
"gobot.io/x/gobot/v2/platforms/raspi"
2014-11-05 09:14:36 +08:00
)
func main() {
r := raspi.NewAdaptor()
led := gpio.NewLedDriver(r, "7")
2014-11-05 09:14:36 +08:00
work := func() {
gobot.Every(1*time.Second, func() {
if err := led.Toggle(); err != nil {
fmt.Println(err)
}
2014-11-05 09:14:36 +08:00
})
}
robot := gobot.NewRobot("blinkBot",
[]gobot.Connection{r},
[]gobot.Device{led},
work,
)
if err := robot.Start(); err != nil {
panic(err)
}
2014-11-05 09:14:36 +08:00
}