MoveHub
is extension of generic Powered Up Hub class. MoveHub
class delivers specifics of MoveHub brick, such as internal motor port names. Apart from specifics listed below, all operations on Hub are done as usual.
As part of instantiating process, MoveHub
waits up to 1 minute for builtin devices to appear, such as motors on ports A and B, tilt sensor, LED and battery. This not guarantees that external motor and/or color sensor will be present right after MoveHub
instantiated. Usually, time.sleep(1.0)
for couple of seconds gives it enough time to detect everything.
MoveHub provides motors via following fields:
motor_A
- port A motormotor_B
- port B motormotor_AB
- combined motors A+B manipulated togethermotor_external
- external motor attached to port C or D
MoveHub's internal tilt sensor is available through tilt_sensor
field.
Field named vision_sensor
holds instance of VisionSensor
, if one is attached to MoveHub.
Fields named current
and voltage
present corresponding sensors from Hub.
MoveHub
class has field button
to subscribe to button press and release events.
Note that Button
class is not real Peripheral
, as it has no port and not listed in peripherals
field of Hub. For convenience, subscribing to button is still done usual way:
from pylgbst.hub import MoveHub
def callback(is_pressed):
print("Btn pressed: %s" % is_pressed)
hub = MoveHub()
hub.button.subscribe(callback)
The state for button has 3 possible values:
0
- not released1
- pressed2
- pressed
It is for now unknown why Hub always issues notification with 1
and immediately with 2
, after button is pressed.