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