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

     1  // +build example
     2  //
     3  // Do not build by default.
     4  
     5  package main
     6  
     7  import (
     8  	"gobot.io/x/gobot/drivers/gpio"
     9  	"gobot.io/x/gobot/platforms/beaglebone"
    10  )
    11  
    12  func main() {
    13  	// Use Gobot to control BeagleBone's digital pins directly
    14  	beagleboneAdaptor := beaglebone.NewAdaptor()
    15  	gpioPin := gpio.NewDirectPinDriver(beagleboneAdaptor, "P9_12")
    16  
    17  	// Initialize the internal representation of the pinout
    18  	beagleboneAdaptor.Connect()
    19  
    20  	// Cast to byte because we are returning an int from a function
    21  	// and not passing in an int literal.
    22  	gpioPin.DigitalWrite(byte(myStateFunction()))
    23  }
    24  
    25  // myStateFunction determines what the GPIO state should be
    26  func myStateFunction() int {
    27  	return 1
    28  }