gobot.io/x/gobot/v2@v2.1.0/examples/particle_led_brightness.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_led_brightness.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/drivers/gpio" 22 "gobot.io/x/gobot/v2/platforms/particle" 23 ) 24 25 func main() { 26 core := particle.NewAdaptor(os.Args[1], os.Args[2]) 27 led := gpio.NewLedDriver(core, "A1") 28 29 work := func() { 30 brightness := uint8(0) 31 fadeAmount := uint8(25) 32 33 gobot.Every(500*time.Millisecond, func() { 34 led.Brightness(brightness) 35 brightness = brightness + fadeAmount 36 if brightness == 0 || brightness == 255 { 37 fadeAmount = -fadeAmount 38 } 39 }) 40 } 41 42 robot := gobot.NewRobot("spark", 43 []gobot.Connection{core}, 44 []gobot.Device{led}, 45 work, 46 ) 47 48 robot.Start() 49 }