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

     1  // +build example
     2  //
     3  // Do not build by default.
     4  
     5  package main
     6  
     7  import (
     8  	"fmt"
     9  
    10  	"gobot.io/x/gobot/drivers/gpio"
    11  	"gobot.io/x/gobot/platforms/intel-iot/edison"
    12  )
    13  
    14  func main() {
    15  	e := edison.NewAdaptor()
    16  	e.Connect()
    17  
    18  	led := gpio.NewLedDriver(e, "13")
    19  	led.Start()
    20  	led.Off()
    21  
    22  	button := gpio.NewButtonDriver(e, "5")
    23  	button.Start()
    24  
    25  	buttonEvents := button.Subscribe()
    26  	for {
    27  		select {
    28  		case event := <-buttonEvents:
    29  			fmt.Println("Event:", event.Name, event.Data)
    30  			if event.Name == gpio.ButtonPush {
    31  				led.Toggle()
    32  			}
    33  		}
    34  	}
    35  }