gobot.io/x/gobot@v1.16.0/examples/joule_led_brightness.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/gpio" 13 "gobot.io/x/gobot/platforms/intel-iot/joule" 14 ) 15 16 func main() { 17 e := joule.NewAdaptor() 18 led := gpio.NewLedDriver(e, "J12_26") 19 20 work := func() { 21 brightness := uint8(0) 22 fadeAmount := uint8(15) 23 24 gobot.Every(100*time.Millisecond, func() { 25 err := led.Brightness(brightness) 26 if err != nil { 27 fmt.Println(err) 28 } 29 brightness = brightness + fadeAmount 30 if brightness == 0 || brightness == 255 { 31 fadeAmount = -fadeAmount 32 } 33 }) 34 } 35 36 robot := gobot.NewRobot("pwmBot", 37 []gobot.Connection{e}, 38 []gobot.Device{led}, 39 work, 40 ) 41 42 robot.Start() 43 }