Skip to content

Instantly share code, notes, and snippets.

@dlech
Last active June 2, 2021 23:30
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 dlech/dddeab5bc970a4691df1ca6ef1ce981c to your computer and use it in GitHub Desktop.
Save dlech/dddeab5bc970a4691df1ca6ef1ce981c to your computer and use it in GitHub Desktop.
Example Pybricks remote control program for SPIKE Prime large drive base (experimental)
from pybricks.hubs import PrimeHub
from pybricks.experimental import Remote
from pybricks.pupdevices import Motor
from pybricks.parameters import Button, Port, Direction
from pybricks.robotics import DriveBase
from pybricks.tools import wait
DRIVE_SPEED = 400
hub = PrimeHub()
left_motor = Motor(Port.A, Direction.COUNTERCLOCKWISE)
right_motor = Motor(Port.E)
print('scanning...')
remote = Remote()
print('connected.')
while True:
remote_buttons = remote.pressed()
if Button.LEFT_UP in remote_buttons:
left_motor.run(DRIVE_SPEED)
elif Button.LEFT_DOWN in remote_buttons:
left_motor.run(-DRIVE_SPEED)
else:
left_motor.stop()
if Button.RIGHT_UP in remote_buttons:
right_motor.run(DRIVE_SPEED)
elif Button.RIGHT_DOWN in remote_buttons:
right_motor.run(-DRIVE_SPEED)
else:
right_motor.stop()
if Button.CENTER in remote_buttons:
hub.speaker.beep(100, -1)
else:
hub.speaker.beep(0, -1)
wait(5)
@dlech
Copy link
Author

dlech commented Jun 2, 2021

SPIKE Prime/MINDSTORMS Robot Inventor firmware download: https://github.com/pybricks/pybricks-micropython/actions/runs/900663479

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment