Skip to content

Instantly share code, notes, and snippets.

@genghisjahn
Created February 6, 2015 03:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save genghisjahn/2411013ac8ac7e4fc98c to your computer and use it in GitHub Desktop.
Save genghisjahn/2411013ac8ac7e4fc98c to your computer and use it in GitHub Desktop.
Sphero Random Roll
package main
import (
"time"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/sphero"
)
func main() {
gbot := gobot.NewGobot()
//tty.Sphero-BBY-AMP-SPP
adaptor := sphero.NewSpheroAdaptor("sphero", "/dev/tty.Sphero-BBY-AMP-SPP")
driver := sphero.NewSpheroDriver(adaptor, "sphero")
driver.SetRGB(255, 0, 0)
b := false
work := func() {
gobot.Every(1*time.Second, func() {
driver.Roll(150, uint16(gobot.Rand(360)))
b = !b
if b == false {
driver.SetRGB(255, 0, 0)
} else {
driver.SetRGB(0, 255, 0)
}
})
}
robot := gobot.NewRobot("sphero",
[]gobot.Connection{adaptor},
[]gobot.Device{driver},
work,
)
gbot.AddRobot(robot)
gbot.Start()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment