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

     1  //go:build example
     2  // +build example
     3  
     4  //
     5  // Do not build by default.
     6  
     7  package main
     8  
     9  import (
    10  	"time"
    11  
    12  	"gobot.io/x/gobot/v2"
    13  	"gobot.io/x/gobot/v2/drivers/gpio"
    14  	"gobot.io/x/gobot/v2/platforms/intel-iot/edison"
    15  )
    16  
    17  func main() {
    18  	e := edison.NewAdaptor()
    19  	led := gpio.NewRgbLedDriver(e, "3", "5", "6")
    20  
    21  	work := func() {
    22  		gobot.Every(1*time.Second, func() {
    23  			r := uint8(gobot.Rand(255))
    24  			g := uint8(gobot.Rand(255))
    25  			b := uint8(gobot.Rand(255))
    26  			led.SetRGB(r, g, b)
    27  		})
    28  	}
    29  
    30  	robot := gobot.NewRobot("rgbBot",
    31  		[]gobot.Connection{e},
    32  		[]gobot.Device{led},
    33  		work,
    34  	)
    35  
    36  	robot.Start()
    37  }