hybridgroup.gobot/examples/digispark_servo.go

34 lines
626 B
Go
Raw Normal View History

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"
)
func main() {
2014-04-28 19:23:15 +08:00
digisparkAdaptor := digispark.NewDigisparkAdaptor()
digisparkAdaptor.Name = "digispark"
2014-04-28 19:23:15 +08:00
servo := gpio.NewServoDriver(digisparkAdaptor)
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},
Devices: []gobot.Device{servo},
Work: work,
}
robot.Start()
}