gobot.io/x/gobot@v1.16.0/examples/firmata_rgb_led.go (about) 1 // +build example 2 // 3 // Do not build by default. 4 5 /* 6 How to run 7 Pass serial port to use as the first param: 8 9 go run examples/firmata_rgb_led.go /dev/ttyACM0 10 */ 11 12 package main 13 14 import ( 15 "os" 16 "time" 17 18 "gobot.io/x/gobot" 19 "gobot.io/x/gobot/drivers/gpio" 20 "gobot.io/x/gobot/platforms/firmata" 21 ) 22 23 func main() { 24 board := firmata.NewAdaptor(os.Args[1]) 25 led := gpio.NewRgbLedDriver(board, "3", "5", "6") 26 27 work := func() { 28 gobot.Every(1*time.Second, func() { 29 r := uint8(gobot.Rand(255)) 30 g := uint8(gobot.Rand(255)) 31 b := uint8(gobot.Rand(255)) 32 led.SetRGB(r, g, b) 33 }) 34 } 35 36 robot := gobot.NewRobot("rgbBot", 37 []gobot.Connection{board}, 38 []gobot.Device{led}, 39 work, 40 ) 41 42 robot.Start() 43 }