hybridgroup.gobot/examples/firmata_motor.go

39 lines
741 B
Go
Raw Normal View History

package main
import (
"github.com/hybridgroup/gobot"
2014-04-28 10:56:18 +08:00
"github.com/hybridgroup/gobot/firmata"
"github.com/hybridgroup/gobot/gpio"
)
func main() {
2014-04-28 10:56:18 +08:00
firmataAdaptor := firmata.NewFirmataAdaptor()
firmataAdaptor.Name = "firmata"
firmataAdaptor.Port = "/dev/ttyACM0"
2014-04-28 10:56:18 +08:00
motor := gpio.NewMotorDriver(firmataAdaptor)
motor.Name = "motor"
motor.SpeedPin = "3"
work := func() {
speed := byte(0)
fade_amount := byte(15)
gobot.Every("0.1s", func() {
motor.Speed(speed)
speed = speed + fade_amount
if speed == 0 || speed == 255 {
fade_amount = -fade_amount
}
})
}
robot := gobot.Robot{
2014-04-28 10:56:18 +08:00
Connections: []gobot.Connection{firmataAdaptor},
Devices: []gobot.Device{motor},
Work: work,
}
robot.Start()
}