mirror of
https://github.com/pybricks/pybricks-api.git
synced 2026-07-27 19:57:02 +00:00
20 lines
540 B
Python
20 lines
540 B
Python
from pybricks.pupdevices import Motor
|
|
from pybricks.parameters import Port
|
|
|
|
from uerrno import ENODEV
|
|
|
|
try:
|
|
# Try to initialize a motor.
|
|
my_motor = Motor(Port.A)
|
|
|
|
# If all goes well, you'll see this message.
|
|
print("Detected a motor.")
|
|
except OSError as ex:
|
|
# If an OSError was raised, we can check what
|
|
# kind of error this was, like ENODEV.
|
|
if ex.errno == ENODEV:
|
|
# ENODEV is short for "Error, no device."
|
|
print("There is no motor this port.")
|
|
else:
|
|
print("Another error occurred.")
|