gobot.io/x/gobot@v1.16.0/examples/particle_api.go (about) 1 // +build example 2 // 3 // Do not build by default. 4 5 /* 6 To run this example, pass the device ID as first param, 7 and the access token as the second param: 8 9 go run examples/particle_api.go mydevice myaccesstoken 10 */ 11 12 package main 13 14 import ( 15 "os" 16 "time" 17 18 "gobot.io/x/gobot" 19 "gobot.io/x/gobot/api" 20 "gobot.io/x/gobot/drivers/gpio" 21 "gobot.io/x/gobot/platforms/particle" 22 ) 23 24 func main() { 25 master := gobot.NewMaster() 26 api.NewAPI(master).Start() 27 28 core := particle.NewAdaptor(os.Args[1], os.Args[2]) 29 led := gpio.NewLedDriver(core, "D7") 30 31 work := func() { 32 gobot.Every(1*time.Second, func() { 33 led.Toggle() 34 }) 35 } 36 37 robot := gobot.NewRobot("spark", 38 []gobot.Connection{core}, 39 []gobot.Device{led}, 40 work, 41 ) 42 43 master.AddRobot(robot) 44 45 master.Start() 46 }