1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-27 13:48:56 +08:00
hybridgroup.gobot/examples/megapi_motor.go
deadprogram acfdbee0cb core: Convert all examples to use new Adaptor/Driver signatures
Signed-off-by: deadprogram <ron@hybridgroup.com>
2016-10-03 16:58:43 +02:00

41 lines
769 B
Go

package main
import (
"time"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/megapi"
)
func main() {
gbot := gobot.NewGobot()
// use "/dev/ttyUSB0" if connecting with USB cable
// use "/dev/ttyAMA0" on devices older than Raspberry Pi 3 Model B
megaPiAdaptor := megapi.NewAdaptor("/dev/ttyS0")
motor := megapi.NewMotorDriver(megaPiAdaptor, 1)
work := func() {
speed := int16(0)
fadeAmount := int16(30)
gobot.Every(100*time.Millisecond, func() {
motor.Speed(speed)
speed = speed + fadeAmount
if speed == 0 || speed == 300 {
fadeAmount = -fadeAmount
}
})
}
robot := gobot.NewRobot("megaPiBot",
[]gobot.Connection{megaPiAdaptor},
[]gobot.Device{motor},
work,
)
gbot.AddRobot(robot)
gbot.Start()
}