gobot.io/x/gobot/v2@v2.1.0/examples/particle_api.go (about)

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