gobot.io/x/gobot@v1.16.0/examples/gopigo3_led_brightness.go (about) 1 // +build example 2 // 3 // Do not build by default. 4 5 package main 6 7 import ( 8 "time" 9 10 "gobot.io/x/gobot" 11 "gobot.io/x/gobot/drivers/gpio" 12 "gobot.io/x/gobot/platforms/dexter/gopigo3" 13 "gobot.io/x/gobot/platforms/raspi" 14 ) 15 16 func main() { 17 raspiAdaptor := raspi.NewAdaptor() 18 gpg3 := gopigo3.NewDriver(raspiAdaptor) 19 led := gpio.NewGroveLedDriver(gpg3, "AD_1_1") 20 21 work := func() { 22 brightness := uint8(0) 23 fadeAmount := uint8(15) 24 25 gobot.Every(100*time.Millisecond, func() { 26 led.Brightness(brightness) 27 brightness = brightness + fadeAmount 28 if brightness == 0 || brightness == 255 { 29 fadeAmount = -fadeAmount 30 } 31 }) 32 } 33 34 robot := gobot.NewRobot("gopigo3pwm", 35 []gobot.Connection{raspiAdaptor}, 36 []gobot.Device{gpg3, led}, 37 work, 38 ) 39 40 robot.Start() 41 }