2016-02-04 05:51:25 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hybridgroup/gobot"
|
|
|
|
"github.com/hybridgroup/gobot/platforms/chip"
|
|
|
|
"github.com/hybridgroup/gobot/platforms/gpio"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
gbot := gobot.NewGobot()
|
|
|
|
|
|
|
|
chipAdaptor := chip.NewChipAdaptor("chip")
|
2016-02-08 16:01:44 +08:00
|
|
|
button := gpio.NewButtonDriver(chipAdaptor, "button", "XIO-P6")
|
|
|
|
led := gpio.NewLedDriver(chipAdaptor, "led", "XIO-P7")
|
2016-02-04 05:51:25 +08:00
|
|
|
|
|
|
|
work := func() {
|
2016-09-01 18:17:43 +08:00
|
|
|
button.On(gpio.ButtonPush, func(data interface{}) {
|
2016-02-04 05:51:25 +08:00
|
|
|
led.On()
|
|
|
|
})
|
|
|
|
|
2016-09-01 18:17:43 +08:00
|
|
|
button.On(gpio.ButtonRelease, func(data interface{}) {
|
2016-02-04 05:51:25 +08:00
|
|
|
led.Off()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("buttonBot",
|
|
|
|
[]gobot.Connection{chipAdaptor},
|
|
|
|
[]gobot.Device{button, led},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
gbot.AddRobot(robot)
|
|
|
|
gbot.Start()
|
|
|
|
}
|