2014-04-26 03:11:51 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hybridgroup/gobot"
|
2016-10-03 16:58:43 +02:00
|
|
|
"github.com/hybridgroup/gobot/drivers/gpio"
|
|
|
|
"github.com/hybridgroup/gobot/platforms/particle"
|
2014-04-26 03:11:51 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-10-15 20:02:54 +02:00
|
|
|
gbot := gobot.NewMaster()
|
2014-04-26 03:11:51 -07:00
|
|
|
|
2016-10-03 16:58:43 +02:00
|
|
|
core := particle.NewAdaptor("device_id", "access_token")
|
|
|
|
led := gpio.NewLedDriver(core, "D7")
|
|
|
|
button := gpio.NewButtonDriver(core, "D5")
|
2014-04-26 03:11:51 -07:00
|
|
|
|
|
|
|
work := func() {
|
2016-08-30 17:53:29 +02:00
|
|
|
button.On(button.Event("push"), func(data interface{}) {
|
2014-04-26 03:11:51 -07:00
|
|
|
led.On()
|
|
|
|
})
|
|
|
|
|
2016-08-30 17:53:29 +02:00
|
|
|
button.On(button.Event("release"), func(data interface{}) {
|
2014-04-26 03:11:51 -07:00
|
|
|
led.Off()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-07-08 18:36:14 -07:00
|
|
|
robot := gobot.NewRobot("spark",
|
2016-10-03 16:58:43 +02:00
|
|
|
[]gobot.Connection{core},
|
2014-07-08 18:36:14 -07:00
|
|
|
[]gobot.Device{button, led},
|
|
|
|
work,
|
|
|
|
)
|
2014-04-26 03:11:51 -07:00
|
|
|
|
2014-07-08 18:36:14 -07:00
|
|
|
gbot.AddRobot(robot)
|
|
|
|
|
|
|
|
gbot.Start()
|
2014-04-26 03:11:51 -07:00
|
|
|
}
|