hybridgroup.gobot/examples/beaglebone_direct_pin.go

35 lines
628 B
Go
Raw Normal View History

package main
import (
2014-07-11 08:21:21 +08:00
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/platforms/beaglebone"
)
func main() {
beagleboneAdaptor := beaglebone.NewAdaptor()
led := gpio.NewDirectPinDriver(beagleboneAdaptor, "P8_10")
button := gpio.NewDirectPinDriver(beagleboneAdaptor, "P8_9")
work := func() {
gobot.Every(500*time.Millisecond, func() {
val, _ := button.DigitalRead()
if val == 1 {
led.DigitalWrite(1)
} else {
led.DigitalWrite(0)
}
})
}
2014-07-09 09:36:14 +08:00
robot := gobot.NewRobot("pinBot",
[]gobot.Connection{beagleboneAdaptor},
[]gobot.Device{led},
work,
)
robot.Start()
}