2015-10-22 16:56:03 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-09-01 13:32:40 +02:00
|
|
|
"github.com/hybridgroup/gobot"
|
2016-10-03 16:58:43 +02:00
|
|
|
"github.com/hybridgroup/gobot/drivers/gpio"
|
2016-09-01 13:32:40 +02:00
|
|
|
"github.com/hybridgroup/gobot/platforms/intel-iot/edison"
|
2015-10-22 16:56:03 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-10-15 20:02:54 +02:00
|
|
|
gbot := gobot.NewMaster()
|
2015-10-22 16:56:03 -07:00
|
|
|
|
2016-10-03 16:58:43 +02:00
|
|
|
e := edison.NewAdaptor()
|
2015-10-22 16:56:03 -07:00
|
|
|
|
2016-10-03 16:58:43 +02:00
|
|
|
button := gpio.NewButtonDriver(e, "2")
|
|
|
|
led := gpio.NewLedDriver(e, "4")
|
2015-10-22 16:56:03 -07:00
|
|
|
|
2016-09-01 13:32:40 +02:00
|
|
|
work := func() {
|
|
|
|
button.On(gpio.ButtonPush, func(data interface{}) {
|
|
|
|
led.On()
|
|
|
|
})
|
|
|
|
button.On(gpio.ButtonRelease, func(data interface{}) {
|
|
|
|
led.Off()
|
|
|
|
})
|
|
|
|
}
|
2015-10-22 16:56:03 -07:00
|
|
|
|
2016-09-01 13:32:40 +02:00
|
|
|
robot := gobot.NewRobot("buttonBot",
|
|
|
|
[]gobot.Connection{e},
|
|
|
|
[]gobot.Device{led, button},
|
|
|
|
work,
|
|
|
|
)
|
2015-10-22 16:56:03 -07:00
|
|
|
|
2016-09-01 13:32:40 +02:00
|
|
|
gbot.AddRobot(robot)
|
2015-10-22 16:56:03 -07:00
|
|
|
|
2016-09-01 13:32:40 +02:00
|
|
|
gbot.Start()
|
2015-10-22 16:56:03 -07:00
|
|
|
}
|