Read values from a Powered Up device and configure its modes.
get(format: Optional[int]) → list¶
Gets the values that the active device
mode(mode: int) → None¶
mode(mode: int, data: bytes) → None
mode(mode: Iterable[Tuple[int, int]]) → None
mode() → Iterable[Tuple[int, int]]
Configures the device mode or multi-mode.
Most Powered Up devices can work in different modes. Each mode makes it do or measure different things. After selecting one mode or a list of modes, the corresponding measured values are accessible via the
Each mode can provide one or more values. For each mode in a multi-mode list, you must select which value of that mode you want. For example, to read value
0as well as values
[(0, 0), (5, 2), (5, 3)]. See
Port.infoto learn which modes can be combined.
Incorrect arguments or incompatible mode settings will be ignored without errors.
mode – A single mode integer or a list of multi-mode tuples.
data – Data to write to the selected mode. When using this argument,
modesmust be a single integer.
When setting the mode, it returns
None. If you don’t give any arguments, this returns the currently active mode.
pwm(value: int) → None¶
Applies a PWM signal to the power pins of the port or device.
A PWM value of 0 has the same effect as
value – PWM value between -100 and +100. The polarity of the PWM signal matches the sign of the value. A value of 0 stops the PWM signal and leaves the port driver in the floating state.
write_direct(data: bytes) → None¶
Sends a message to the device using the wired Powered Up protocol.
The data must be formatted using the Powered Up specification, which may include a command or message type and a payload. The required checksum will be added automatically.
data – The Powered Up data message. Must not exceed 9 bytes.
The data has no particular unit.
The data is a percentage.
The data has SI units, if available.