mirror of
https://github.com/hybridgroup/gobot.git
synced 2025-05-02 22:17:12 +08:00
40 lines
636 B
Go
40 lines
636 B
Go
package main
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/hybridgroup/gobot"
|
|
"github.com/hybridgroup/gobot/drivers/gpio"
|
|
"github.com/hybridgroup/gobot/platforms/firmata"
|
|
)
|
|
|
|
func main() {
|
|
gbot := gobot.NewMaster()
|
|
|
|
firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0")
|
|
pin := gpio.NewDirectPinDriver(firmataAdaptor, "13")
|
|
|
|
work := func() {
|
|
level := byte(1)
|
|
|
|
gobot.Every(1*time.Second, func() {
|
|
pin.DigitalWrite(level)
|
|
if level == 1 {
|
|
level = 0
|
|
} else {
|
|
level = 1
|
|
}
|
|
})
|
|
}
|
|
|
|
robot := gobot.NewRobot("pinBot",
|
|
[]gobot.Connection{firmataAdaptor},
|
|
[]gobot.Device{pin},
|
|
work,
|
|
)
|
|
|
|
gbot.AddRobot(robot)
|
|
|
|
gbot.Start()
|
|
}
|