mirror of
https://github.com/pybricks/pybricks-api.git
synced 2026-09-15 11:04:55 +00:00
25 lines
725 B
Python
25 lines
725 B
Python
from pybricks.pupdevices import Motor
|
|
from pybricks.parameters import Port
|
|
from pybricks.tools import wait
|
|
from pybricks.messaging import BLERadio
|
|
|
|
# Initialize the hub.
|
|
radio = BLERadio(broadcast_channel=1)
|
|
|
|
# Initialize the motors.
|
|
left_motor = Motor(Port.A)
|
|
right_motor = Motor(Port.B)
|
|
|
|
while True:
|
|
# Read the motor angles to be sent to the other hub.
|
|
left_angle = left_motor.angle()
|
|
right_angle = right_motor.angle()
|
|
|
|
# Set the broadcast data and start broadcasting if not already doing so.
|
|
data = (left_angle, right_angle)
|
|
radio.broadcast(data)
|
|
|
|
# Broadcasts are only sent every 100 milliseconds, so there is no reason
|
|
# to call the broadcast() method more often than that.
|
|
wait(100)
|