-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Includes a sample program to show how it works.
- Loading branch information
1 parent
cd653e9
commit 87c0572
Showing
2 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
//go:build example | ||
// +build example | ||
|
||
// | ||
// Do not build by default. | ||
|
||
package main | ||
|
||
import ( | ||
"gobot.io/x/gobot/v2" | ||
"gobot.io/x/gobot/v2/api" | ||
"gobot.io/x/gobot/v2/platforms/keyboard" | ||
"gobot.io/x/gobot/v2/platforms/sphero" | ||
) | ||
|
||
func main() { | ||
master := gobot.NewMaster() | ||
a := api.NewAPI(master) | ||
a.Start() | ||
|
||
ballConn := sphero.NewAdaptor("/dev/rfcomm0") | ||
ball := sphero.NewSpheroDriver(ballConn) | ||
|
||
keys := keyboard.NewDriver() | ||
|
||
calibrating := false | ||
|
||
work := func() { | ||
keys.On(keyboard.Key, func(data interface{}) { | ||
key := data.(keyboard.KeyEvent) | ||
|
||
switch key.Key { | ||
case keyboard.ArrowUp: | ||
if calibrating { | ||
break | ||
} | ||
ball.Roll(100, 0) | ||
case keyboard.ArrowDown: | ||
if calibrating { | ||
break | ||
} | ||
ball.Roll(100, 100) | ||
case keyboard.ArrowLeft: | ||
ball.Roll(100, 270) | ||
case keyboard.ArrowRight: | ||
ball.Roll(100, 90) | ||
case keyboard.Spacebar: | ||
if calibrating { | ||
ball.FinishCalibration() | ||
} else { | ||
ball.StartCalibration() | ||
} | ||
calibrating = !calibrating | ||
} | ||
}) | ||
} | ||
|
||
robot := gobot.NewRobot("sphero-calibration", | ||
[]gobot.Connection{ballConn}, | ||
[]gobot.Device{ball, keys}, | ||
work, | ||
) | ||
|
||
master.AddRobot(robot) | ||
|
||
master.Start() | ||
} |
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