2014-06-12 02:44:10 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2014-07-11 08:21:21 +08:00
|
|
|
"time"
|
|
|
|
|
2014-06-12 02:44:10 +08:00
|
|
|
"github.com/hybridgroup/gobot"
|
|
|
|
"github.com/hybridgroup/gobot/platforms/firmata"
|
|
|
|
"github.com/hybridgroup/gobot/platforms/gpio"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
gbot := gobot.NewGobot()
|
2014-07-09 09:36:14 +08:00
|
|
|
|
2014-06-12 02:44:10 +08:00
|
|
|
firmataAdaptor := firmata.NewFirmataAdaptor("myFirmata", "/dev/ttyACM0")
|
|
|
|
pin := gpio.NewDirectPinDriver(firmataAdaptor, "pin", "13")
|
2014-07-09 09:36:14 +08:00
|
|
|
|
2014-06-12 02:44:10 +08:00
|
|
|
work := func() {
|
|
|
|
level := byte(1)
|
|
|
|
|
|
|
|
gobot.Every(1*time.Second, func() {
|
|
|
|
pin.DigitalWrite(level)
|
|
|
|
if level == 1 {
|
|
|
|
level = 0
|
|
|
|
} else {
|
|
|
|
level = 1
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2014-07-09 09:36:14 +08:00
|
|
|
|
|
|
|
robot := gobot.NewRobot("pinBot",
|
|
|
|
[]gobot.Connection{firmataAdaptor},
|
|
|
|
[]gobot.Device{pin},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
|
|
|
gbot.AddRobot(robot)
|
|
|
|
|
2014-06-12 02:44:10 +08:00
|
|
|
gbot.Start()
|
|
|
|
}
|