2014-06-29 02:05:17 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2014-07-11 08:21:21 +08:00
|
|
|
"time"
|
|
|
|
|
2014-06-29 02:05:17 +08:00
|
|
|
"github.com/hybridgroup/gobot"
|
|
|
|
"github.com/hybridgroup/gobot/platforms/beaglebone"
|
|
|
|
"github.com/hybridgroup/gobot/platforms/gpio"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
gbot := gobot.NewGobot()
|
|
|
|
|
|
|
|
beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
|
|
|
|
led := gpio.NewDirectPinDriver(beagleboneAdaptor, "led", "P8_10")
|
|
|
|
button := gpio.NewDirectPinDriver(beagleboneAdaptor, "button", "P8_9")
|
|
|
|
|
|
|
|
work := func() {
|
|
|
|
gobot.Every(500*time.Millisecond, func() {
|
|
|
|
if button.DigitalRead() == 1 {
|
|
|
|
led.DigitalWrite(1)
|
|
|
|
} else {
|
|
|
|
led.DigitalWrite(0)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-07-09 09:36:14 +08:00
|
|
|
robot := gobot.NewRobot("pinBot",
|
|
|
|
[]gobot.Connection{beagleboneAdaptor},
|
|
|
|
[]gobot.Device{led},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
|
|
|
gbot.AddRobot(robot)
|
|
|
|
|
2014-06-29 02:05:17 +08:00
|
|
|
gbot.Start()
|
|
|
|
}
|