gobot.io/x/gobot@v1.16.0/examples/beaglebone_direct_pin.go (about) 1 // +build example 2 // 3 // Do not build by default. 4 5 package main 6 7 import ( 8 "time" 9 10 "gobot.io/x/gobot" 11 "gobot.io/x/gobot/drivers/gpio" 12 "gobot.io/x/gobot/platforms/beaglebone" 13 ) 14 15 func main() { 16 beagleboneAdaptor := beaglebone.NewAdaptor() 17 led := gpio.NewDirectPinDriver(beagleboneAdaptor, "P8_10") 18 button := gpio.NewDirectPinDriver(beagleboneAdaptor, "P8_09") 19 20 work := func() { 21 gobot.Every(500*time.Millisecond, func() { 22 val, _ := button.DigitalRead() 23 if val == 1 { 24 led.DigitalWrite(1) 25 } else { 26 led.DigitalWrite(0) 27 } 28 }) 29 } 30 31 robot := gobot.NewRobot("pinBot", 32 []gobot.Connection{beagleboneAdaptor}, 33 []gobot.Device{led}, 34 work, 35 ) 36 37 robot.Start() 38 }