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

     1  //go:build example
     2  // +build example
     3  
     4  //
     5  // Do not build by default.
     6  
     7  /*
     8   How to run
     9   Pass serial port to use as the first param:
    10  
    11  	go run examples/firmata_rgb_led.go /dev/ttyACM0
    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/firmata"
    23  )
    24  
    25  func main() {
    26  	board := firmata.NewAdaptor(os.Args[1])
    27  	led := gpio.NewRgbLedDriver(board, "3", "5", "6")
    28  
    29  	work := func() {
    30  		gobot.Every(1*time.Second, func() {
    31  			r := uint8(gobot.Rand(255))
    32  			g := uint8(gobot.Rand(255))
    33  			b := uint8(gobot.Rand(255))
    34  			led.SetRGB(r, g, b)
    35  		})
    36  	}
    37  
    38  	robot := gobot.NewRobot("rgbBot",
    39  		[]gobot.Connection{board},
    40  		[]gobot.Device{led},
    41  		work,
    42  	)
    43  
    44  	robot.Start()
    45  }