2014-04-26 03:11:51 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/hybridgroup/gobot"
|
2014-04-27 19:56:18 -07:00
|
|
|
"github.com/hybridgroup/gobot/firmata"
|
|
|
|
"github.com/hybridgroup/gobot/gpio"
|
2014-04-26 03:11:51 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2014-04-27 19:56:18 -07:00
|
|
|
firmataAdaptor := firmata.NewFirmataAdaptor()
|
|
|
|
firmataAdaptor.Name = "firmata"
|
|
|
|
firmataAdaptor.Port = "/dev/ttyACM0"
|
2014-04-26 03:11:51 -07:00
|
|
|
|
2014-04-27 19:56:18 -07:00
|
|
|
servo := gpio.NewServoDriver(firmataAdaptor)
|
2014-04-26 03:11:51 -07:00
|
|
|
servo.Name = "servo"
|
|
|
|
servo.Pin = "3"
|
|
|
|
|
|
|
|
work := func() {
|
|
|
|
gobot.Every("1s", func() {
|
|
|
|
i := uint8(gobot.Rand(180))
|
|
|
|
fmt.Println("Turning", i)
|
|
|
|
servo.Move(i)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.Robot{
|
2014-04-27 19:56:18 -07:00
|
|
|
Connections: []gobot.Connection{firmataAdaptor},
|
2014-04-26 03:11:51 -07:00
|
|
|
Devices: []gobot.Device{servo},
|
|
|
|
Work: work,
|
|
|
|
}
|
|
|
|
|
|
|
|
robot.Start()
|
|
|
|
}
|