gobot.io/x/gobot@v1.16.0/examples/chip_button_led.go (about)

     1  // +build example
     2  //
     3  // Do not build by default.
     4  
     5  package main
     6  
     7  import (
     8  	"gobot.io/x/gobot"
     9  	"gobot.io/x/gobot/drivers/gpio"
    10  	"gobot.io/x/gobot/platforms/chip"
    11  )
    12  
    13  func main() {
    14  	chipAdaptor := chip.NewAdaptor()
    15  	button := gpio.NewButtonDriver(chipAdaptor, "XIO-P6")
    16  	led := gpio.NewLedDriver(chipAdaptor, "XIO-P7")
    17  
    18  	work := func() {
    19  		button.On(gpio.ButtonPush, func(data interface{}) {
    20  			led.On()
    21  		})
    22  
    23  		button.On(gpio.ButtonRelease, func(data interface{}) {
    24  			led.Off()
    25  		})
    26  	}
    27  
    28  	robot := gobot.NewRobot("buttonBot",
    29  		[]gobot.Connection{chipAdaptor},
    30  		[]gobot.Device{button, led},
    31  		work,
    32  	)
    33  
    34  	robot.Start()
    35  }