2014-09-19 03:45:54 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hybridgroup/gobot"
|
2016-10-03 22:58:43 +08:00
|
|
|
"github.com/hybridgroup/gobot/drivers/gpio"
|
2014-09-19 03:45:54 +08:00
|
|
|
"github.com/hybridgroup/gobot/platforms/intel-iot/edison"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
gbot := gobot.NewGobot()
|
|
|
|
|
2016-10-03 22:58:43 +08:00
|
|
|
e := edison.NewAdaptor()
|
2014-09-19 03:45:54 +08:00
|
|
|
|
2016-10-03 22:58:43 +08:00
|
|
|
button := gpio.NewButtonDriver(e, "5")
|
|
|
|
led := gpio.NewLedDriver(e, "13")
|
2014-09-19 03:45:54 +08:00
|
|
|
|
|
|
|
work := func() {
|
2016-09-01 18:17:43 +08:00
|
|
|
button.On(gpio.ButtonPush, func(data interface{}) {
|
2014-09-19 03:45:54 +08:00
|
|
|
led.On()
|
|
|
|
})
|
2016-09-01 18:17:43 +08:00
|
|
|
button.On(gpio.ButtonRelease, func(data interface{}) {
|
2014-09-19 03:45:54 +08:00
|
|
|
led.Off()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("buttonBot",
|
|
|
|
[]gobot.Connection{e},
|
|
|
|
[]gobot.Device{led, button},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
|
|
|
gbot.AddRobot(robot)
|
|
|
|
|
|
|
|
gbot.Start()
|
|
|
|
}
|