Created
February 6, 2015 03:42
-
-
Save genghisjahn/2411013ac8ac7e4fc98c to your computer and use it in GitHub Desktop.
Sphero Random Roll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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