2014-04-26 18:11:51 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/hybridgroup/gobot"
|
2014-04-28 19:23:15 +08:00
|
|
|
"github.com/hybridgroup/gobot/digispark"
|
|
|
|
"github.com/hybridgroup/gobot/gpio"
|
2014-04-26 18:11:51 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2014-04-28 19:23:15 +08:00
|
|
|
digisparkAdaptor := digispark.NewDigisparkAdaptor()
|
|
|
|
digisparkAdaptor.Name = "digispark"
|
2014-04-26 18:11:51 +08:00
|
|
|
|
2014-04-28 19:23:15 +08:00
|
|
|
servo := gpio.NewServoDriver(digisparkAdaptor)
|
2014-04-26 18:11:51 +08:00
|
|
|
servo.Name = "servo"
|
|
|
|
servo.Pin = "0"
|
|
|
|
|
|
|
|
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:23:15 +08:00
|
|
|
Connections: []gobot.Connection{digisparkAdaptor},
|
2014-04-26 18:11:51 +08:00
|
|
|
Devices: []gobot.Device{servo},
|
|
|
|
Work: work,
|
|
|
|
}
|
|
|
|
|
|
|
|
robot.Start()
|
|
|
|
}
|