1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-26 13:48:49 +08:00
hybridgroup.gobot/examples/beaglebone_direct_pin.go

39 lines
714 B
Go
Raw Normal View History

package main
import (
2014-07-10 17:21:21 -07:00
"time"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/drivers/gpio"
"github.com/hybridgroup/gobot/platforms/beaglebone"
)
func main() {
gbot := gobot.NewMaster()
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-08 18:36:14 -07:00
robot := gobot.NewRobot("pinBot",
[]gobot.Connection{beagleboneAdaptor},
[]gobot.Device{led},
work,
)
gbot.AddRobot(robot)
gbot.Start()
}