gobot.io/x/gobot/v2@v2.1.0/examples/beaglebone_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  	"time"
    11  
    12  	"gobot.io/x/gobot/v2"
    13  	"gobot.io/x/gobot/v2/drivers/gpio"
    14  	"gobot.io/x/gobot/v2/platforms/beaglebone"
    15  )
    16  
    17  func main() {
    18  	beagleboneAdaptor := beaglebone.NewAdaptor()
    19  	led := gpio.NewDirectPinDriver(beagleboneAdaptor, "P8_10")
    20  	button := gpio.NewDirectPinDriver(beagleboneAdaptor, "P8_09")
    21  
    22  	work := func() {
    23  		gobot.Every(500*time.Millisecond, func() {
    24  			val, _ := button.DigitalRead()
    25  			if val == 1 {
    26  				led.DigitalWrite(1)
    27  			} else {
    28  				led.DigitalWrite(0)
    29  			}
    30  		})
    31  	}
    32  
    33  	robot := gobot.NewRobot("pinBot",
    34  		[]gobot.Connection{beagleboneAdaptor},
    35  		[]gobot.Device{led},
    36  		work,
    37  	)
    38  
    39  	robot.Start()
    40  }