1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-27 13:48:56 +08:00

50 lines
960 B
Go
Raw Normal View History

// +build example
//
// Do not build by default.
2013-11-13 20:49:57 -08:00
package main
import (
2014-04-26 18:07:04 -07:00
"fmt"
2014-07-09 09:38:43 -07:00
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/platforms/sphero"
2013-11-13 20:49:57 -08:00
)
func main() {
adaptor := sphero.NewAdaptor("/dev/rfcomm0")
spheroDriver := sphero.NewSpheroDriver(adaptor)
2013-11-13 20:49:57 -08:00
work := func() {
spheroDriver.SetDataStreaming(sphero.DefaultDataStreamingConfig())
spheroDriver.On(sphero.Collision, func(data interface{}) {
fmt.Printf("Collision! %+v\n", data)
})
spheroDriver.On(sphero.SensorData, func(data interface{}) {
fmt.Printf("Streaming Data! %+v\n", data)
2014-04-26 18:07:04 -07:00
})
2014-05-22 21:20:16 -07:00
gobot.Every(3*time.Second, func() {
2014-04-28 11:40:20 -07:00
spheroDriver.Roll(30, uint16(gobot.Rand(360)))
2014-04-26 18:07:04 -07:00
})
2014-05-22 21:20:16 -07:00
gobot.Every(1*time.Second, func() {
2014-04-26 18:07:04 -07:00
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
})
}
2014-07-08 18:36:14 -07:00
robot := gobot.NewRobot("sphero",
[]gobot.Connection{adaptor},
[]gobot.Device{spheroDriver},
work,
)
robot.Start()
2013-11-13 20:49:57 -08:00
}