gobot.io/x/gobot/v2@v2.1.0/examples/beaglebone_blinkm.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  	"fmt"
    11  	"time"
    12  
    13  	"gobot.io/x/gobot/v2"
    14  	"gobot.io/x/gobot/v2/drivers/i2c"
    15  	"gobot.io/x/gobot/v2/platforms/beaglebone"
    16  )
    17  
    18  func main() {
    19  	beagleboneAdaptor := beaglebone.NewAdaptor()
    20  	blinkm := i2c.NewBlinkMDriver(beagleboneAdaptor)
    21  
    22  	work := func() {
    23  		gobot.Every(1*time.Second, func() {
    24  			r := byte(gobot.Rand(255))
    25  			g := byte(gobot.Rand(255))
    26  			b := byte(gobot.Rand(255))
    27  			blinkm.Rgb(r, g, b)
    28  			color, _ := blinkm.Color()
    29  			fmt.Println("color", color)
    30  		})
    31  	}
    32  
    33  	robot := gobot.NewRobot("blinkmBot",
    34  		[]gobot.Connection{beagleboneAdaptor},
    35  		[]gobot.Device{blinkm},
    36  		work,
    37  	)
    38  
    39  	robot.Start()
    40  }