2014-04-26 18:11:51 +08:00
|
|
|
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"
|
2014-04-26 18:11:51 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2014-04-28 10:56:18 +08:00
|
|
|
firmataAdaptor := firmata.NewFirmataAdaptor()
|
|
|
|
firmataAdaptor.Name = "firmata"
|
|
|
|
firmataAdaptor.Port = "/dev/ttyACM0"
|
2014-04-26 18:11:51 +08:00
|
|
|
|
2014-04-28 10:56:18 +08:00
|
|
|
motor := gpio.NewMotorDriver(firmataAdaptor)
|
2014-04-26 18:11:51 +08:00
|
|
|
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},
|
2014-04-26 18:11:51 +08:00
|
|
|
Devices: []gobot.Device{motor},
|
|
|
|
Work: work,
|
|
|
|
}
|
|
|
|
|
|
|
|
robot.Start()
|
|
|
|
}
|