2014-04-26 18:11:51 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"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
|
|
|
master := gobot.NewMaster()
|
2014-04-26 18:11:51 +08:00
|
|
|
gobot.Api(master)
|
|
|
|
|
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
|
|
|
led := gpio.NewLed(sparkCore)
|
2014-04-26 18:11:51 +08:00
|
|
|
led.Name = "led"
|
|
|
|
led.Pin = "D7"
|
|
|
|
|
|
|
|
work := func() {
|
|
|
|
gobot.Every("1s", func() {
|
|
|
|
led.Toggle()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
master.Robots = append(master.Robots, &gobot.Robot{
|
|
|
|
Name: "spark",
|
2014-04-28 02:56:23 +08:00
|
|
|
Connections: []gobot.Connection{sparkCore},
|
2014-04-26 18:11:51 +08:00
|
|
|
Devices: []gobot.Device{led},
|
|
|
|
Work: work,
|
|
|
|
})
|
|
|
|
|
|
|
|
master.Start()
|
|
|
|
}
|