hybridgroup.gobot/examples/beaglebone_servo.go

34 lines
638 B
Go
Raw Normal View History

package main
import (
"fmt"
"github.com/hybridgroup/gobot"
2014-04-28 19:39:51 +08:00
"github.com/hybridgroup/gobot/beaglebone"
"github.com/hybridgroup/gobot/gpio"
)
func main() {
2014-04-28 19:39:51 +08:00
beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor()
beagleboneAdaptor.Name = "beaglebone"
2014-04-28 19:39:51 +08:00
servo := gpio.NewServoDriver(beagleboneAdaptor)
servo.Name = "servo"
servo.Pin = "P9_14"
work := func() {
gobot.Every("1s", func() {
i := uint8(gobot.Rand(180))
fmt.Println("Turning", i)
servo.Move(i)
})
}
robot := gobot.Robot{
2014-04-28 19:39:51 +08:00
Connections: []gobot.Connection{beagleboneAdaptor},
Devices: []gobot.Device{servo},
Work: work,
}
robot.Start()
}