2014-04-26 18:11:51 +08:00
|
|
|
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"
|
2014-04-26 18:11:51 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2014-04-28 19:39:51 +08:00
|
|
|
beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor()
|
|
|
|
beagleboneAdaptor.Name = "beaglebone"
|
2014-04-26 18:11:51 +08:00
|
|
|
|
2014-04-28 19:39:51 +08:00
|
|
|
servo := gpio.NewServoDriver(beagleboneAdaptor)
|
2014-04-26 18:11:51 +08:00
|
|
|
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},
|
2014-04-26 18:11:51 +08:00
|
|
|
Devices: []gobot.Device{servo},
|
|
|
|
Work: work,
|
|
|
|
}
|
|
|
|
|
|
|
|
robot.Start()
|
|
|
|
}
|