2014-04-26 18:11:51 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/hybridgroup/gobot"
|
2014-04-28 02:56:23 +08:00
|
|
|
"github.com/hybridgroup/gobot/gpio"
|
|
|
|
"github.com/hybridgroup/gobot/spark"
|
2014-04-26 18:11:51 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2014-04-28 02:56:23 +08:00
|
|
|
sparkCore := spark.NewSparkCoreAdaptor()
|
|
|
|
sparkCore.Name = "spark"
|
|
|
|
sparkCore.Params = map[string]interface{}{
|
2014-04-26 18:11:51 +08:00
|
|
|
"device_id": "",
|
|
|
|
"access_token": "",
|
|
|
|
}
|
|
|
|
|
2014-04-28 02:56:23 +08:00
|
|
|
button := gpio.NewButton(sparkCore)
|
2014-04-26 18:11:51 +08:00
|
|
|
button.Name = "button"
|
|
|
|
button.Pin = "D5"
|
|
|
|
button.Interval = "2s"
|
|
|
|
|
2014-04-28 02:56:23 +08:00
|
|
|
led := gpio.NewLed(sparkCore)
|
2014-04-26 18:11:51 +08:00
|
|
|
led.Name = "led"
|
|
|
|
led.Pin = "D7"
|
|
|
|
|
|
|
|
work := func() {
|
|
|
|
gobot.On(button.Events["push"], func(data interface{}) {
|
|
|
|
led.On()
|
|
|
|
})
|
|
|
|
|
|
|
|
gobot.On(button.Events["release"], func(data interface{}) {
|
|
|
|
led.Off()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.Robot{
|
2014-04-28 02:56:23 +08:00
|
|
|
Connections: []gobot.Connection{sparkCore},
|
2014-04-26 18:11:51 +08:00
|
|
|
Devices: []gobot.Device{button, led},
|
|
|
|
Work: work,
|
|
|
|
}
|
|
|
|
|
|
|
|
robot.Start()
|
|
|
|
}
|