hybridgroup.gobot/examples/sphero.go

42 lines
779 B
Go
Raw Normal View History

2013-11-14 12:49:57 +08:00
package main
import (
2014-04-27 09:07:04 +08:00
"fmt"
2013-12-03 16:48:20 +08:00
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/sphero"
2013-11-14 12:49:57 +08:00
)
func main() {
2014-04-27 09:07:04 +08:00
adaptor := sphero.NewAdaptor()
adaptor.Name = "Sphero"
adaptor.Port = "/dev/rfcomm0"
2013-11-14 12:49:57 +08:00
2014-04-27 09:07:04 +08:00
sphero := sphero.NewSphero(adaptor)
sphero.Name = "sphero"
2013-11-14 12:49:57 +08:00
work := func() {
2014-04-27 09:07:04 +08:00
gobot.On(sphero.Events["Collision"], func(data interface{}) {
fmt.Println("Collision Detected!")
})
gobot.Every("3s", func() {
sphero.Roll(30, uint16(gobot.Rand(360)))
})
gobot.Every("1s", func() {
r := uint8(gobot.Rand(255))
g := uint8(gobot.Rand(255))
b := uint8(gobot.Rand(255))
sphero.SetRGB(r, g, b)
2013-11-14 12:49:57 +08:00
})
}
robot := gobot.Robot{
2014-04-27 09:07:04 +08:00
Connections: []gobot.Connection{adaptor},
2013-12-31 05:56:16 +08:00
Devices: []gobot.Device{sphero},
2013-11-14 12:49:57 +08:00
Work: work,
}
robot.Start()
}