Last active
June 2, 2021 23:30
-
-
Save dlech/dddeab5bc970a4691df1ca6ef1ce981c to your computer and use it in GitHub Desktop.
Example Pybricks remote control program for SPIKE Prime large drive base (experimental)
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
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) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SPIKE Prime/MINDSTORMS Robot Inventor firmware download: https://github.com/pybricks/pybricks-micropython/actions/runs/900663479