1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-26 13:48:49 +08:00
hybridgroup.gobot/examples/firmata_servo.go

36 lines
574 B
Go
Raw Normal View History

// +build example
//
// Do not build by default.
package main
import (
"fmt"
2014-07-10 17:21:21 -07:00
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/platforms/firmata"
)
func main() {
firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0")
servo := gpio.NewServoDriver(firmataAdaptor, "3")
work := func() {
2014-05-22 19:22:14 -07:00
gobot.Every(1*time.Second, func() {
i := uint8(gobot.Rand(180))
fmt.Println("Turning", i)
servo.Move(i)
})
}
2014-07-08 18:36:14 -07:00
robot := gobot.NewRobot("servoBot",
[]gobot.Connection{firmataAdaptor},
[]gobot.Device{servo},
work,
)
robot.Start()
}