gobot.io/x/gobot/v2@v2.1.0/examples/beaglebone_basic_direct_pin.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  	"gobot.io/x/gobot/v2/drivers/gpio"
    11  	"gobot.io/x/gobot/v2/platforms/beaglebone"
    12  )
    13  
    14  func main() {
    15  	// Use Gobot to control BeagleBone's digital pins directly
    16  	beagleboneAdaptor := beaglebone.NewAdaptor()
    17  	gpioPin := gpio.NewDirectPinDriver(beagleboneAdaptor, "P9_12")
    18  
    19  	// Initialize the internal representation of the pinout
    20  	beagleboneAdaptor.Connect()
    21  
    22  	// Cast to byte because we are returning an int from a function
    23  	// and not passing in an int literal.
    24  	gpioPin.DigitalWrite(byte(myStateFunction()))
    25  }
    26  
    27  // myStateFunction determines what the GPIO state should be
    28  func myStateFunction() int {
    29  	return 1
    30  }