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