gobot.io/x/gobot@v1.16.0/examples/edison_blinkm.go (about)

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