2023-05-20 20:25:21 +08:00
|
|
|
//go:build example
|
2018-08-14 06:21:46 +08:00
|
|
|
// +build example
|
2023-05-20 20:25:21 +08:00
|
|
|
|
2018-08-14 06:21:46 +08:00
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-02-11 22:34:50 +08:00
|
|
|
"fmt"
|
2018-08-14 06:21:46 +08:00
|
|
|
"time"
|
|
|
|
|
2023-05-20 20:25:21 +08:00
|
|
|
"gobot.io/x/gobot/v2"
|
|
|
|
"gobot.io/x/gobot/v2/drivers/gpio"
|
|
|
|
"gobot.io/x/gobot/v2/drivers/i2c"
|
|
|
|
"gobot.io/x/gobot/v2/platforms/raspi"
|
2018-08-14 06:21:46 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
r := raspi.NewAdaptor()
|
|
|
|
gp := i2c.NewGrovePiDriver(r)
|
2018-08-14 16:24:07 +08:00
|
|
|
led := gpio.NewLedDriver(gp, "D2")
|
2018-08-14 06:21:46 +08:00
|
|
|
|
|
|
|
work := func() {
|
|
|
|
gobot.Every(1*time.Second, func() {
|
2024-02-11 22:34:50 +08:00
|
|
|
if err := led.Toggle(); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
2018-08-14 06:21:46 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("blinkBot",
|
|
|
|
[]gobot.Connection{r},
|
|
|
|
[]gobot.Device{gp, led},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
2024-02-11 22:34:50 +08:00
|
|
|
if err := robot.Start(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2018-08-14 06:21:46 +08:00
|
|
|
}
|