1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-29 13:49:14 +08:00

42 lines
821 B
Go
Raw Normal View History

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