hybridgroup.gobot/examples/spark_core_api.go

39 lines
697 B
Go
Raw Normal View History

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"
)
func main() {
2014-04-28 02:56:23 +08:00
master := gobot.NewMaster()
gobot.Api(master)
2014-04-28 02:56:23 +08:00
sparkCore := spark.NewSparkCoreAdaptor()
sparkCore.Name = "spark"
sparkCore.Params = map[string]interface{}{
"device_id": "",
"access_token": "",
}
2014-04-28 02:56:23 +08:00
led := gpio.NewLed(sparkCore)
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},
Devices: []gobot.Device{led},
Work: work,
})
master.Start()
}