lpf2.devices
The motors, sensors and lights you can plug into a port.
You don’t create these yourself: ask the port with
hub.ports.A.device() and you get the right one for whatever is
plugged in, with functions that fit that device.
Classes
The hub's built-in accelerometer ( |
|
A simple motor without a rotation sensor, like a train motor. You can set its power, but not its exact speed or position. |
|
The BOOST Color & Distance Sensor: sees colors and roughly how far away things are. |
|
The Technic Color Sensor: sees colors and how much light bounces back. |
|
The Technic Distance Sensor (the one with two "eyes"): measures how far away things are. |
|
A motor with a rotation sensor (most Technic and BOOST motors). |
|
The hub's built-in gyroscope ( |
|
A hub's built-in colored light ( |
|
A Port Expander: plugs into one port and gives you four more. |
Functions
|
Advanced: teach the hub about the standard LEGO devices again. |
Package Contents
- class lpf2.devices.accelerometer[source]
The hub’s built-in accelerometer (
hub.accelerometer): measures pushes and gravity in milli-g (1000 = gravity).- getDeviceType() int[source]
A number saying what kind of device this is (see
lpf2.device_type).
- class lpf2.devices.basic_motor[source]
A simple motor without a rotation sensor, like a train motor. You can set its power, but not its exact speed or position.
- getDeviceType() int[source]
A number saying what kind of device this is (see
lpf2.device_type).
- class lpf2.devices.color_distance_sensor[source]
The BOOST Color & Distance Sensor: sees colors and roughly how far away things are.
- getColorIdx() int[source]
The color it sees, as a number from
lpf2.color(e.g. compare withcolor.RED).
- getDeviceType() int[source]
A number saying what kind of device this is (see
lpf2.device_type).
- getReflectedLight() int[source]
How much light bounces back from the surface, 0..100 %. White paper is high, black is low.
- setIrTx(value: int) None[source]
Advanced: send an infrared code, like an old LEGO Power Functions remote.
- setLedColor(color: int) None[source]
Set the sensor’s light to a color from
lpf2.color.
- class lpf2.devices.color_sensor[source]
The Technic Color Sensor: sees colors and how much light bounces back.
All its readings are kept up to date at the same time, so you can call any of the
get…functions whenever you like.- getColorIdx() int[source]
The color it sees, as a number from
lpf2.color(e.g. compare withcolor.RED).
- getDeviceType() int[source]
A number saying what kind of device this is (see
lpf2.device_type).
- getHSV() tuple[int, int, int][source]
The color as hue (0..360, the color wheel angle), saturation (0..100) and value/brightness:
h, s, v = sensor.getHSV().
- getRGB() tuple[int, int, int, int][source]
How much red, green and blue it sees, plus overall brightness:
r, g, b, i = sensor.getRGB().
- getReflectivity() float[source]
How much light bounces back from the surface, 0..100 %. White paper is high, black is low.
- setLight(l1: int, l2: int, l3: int) None[source]
Set the brightness of the sensor’s three lights, each 0..100 %.
- class lpf2.devices.distance_sensor[source]
The Technic Distance Sensor (the one with two “eyes”): measures how far away things are.
- getDeviceType() int[source]
A number saying what kind of device this is (see
lpf2.device_type).
- setLight(l1: int, l2: int, l3: int, l4: int) None[source]
Set the brightness of the four lights around the eyes, each 0..100 %.
- class lpf2.devices.encoder_motor[source]
A motor with a rotation sensor (most Technic and BOOST motors).
It can hold a steady speed, turn an exact number of degrees, or go to a position.
- getDeviceType() int[source]
A number saying what kind of device this is (see
lpf2.device_type).
- gotoAbsPosition(absPos: int, speed: int = 100, maxPower: int = 100, endState: int = 0, useProfile: int = 0) None[source]
Turn to position
absPosdegrees, then stop.Position 0 is set with
presetEncoder().endState:0= coast,127= brake,126= hold position.
- presetEncoder(pos: int) None[source]
Stop the motor and call its current position
posdegrees (usually 0).
- setAccTime(time: int, profile: int) None[source]
How long (ms) the motor takes to speed up, stored in slot
profile(0..15).
- setDecTime(time: int, profile: int) None[source]
How long (ms) the motor takes to slow down, stored in slot
profile(0..15).
- startPower(pw: int) None[source]
Run the motor at a power from -100 to 100. The sign sets the direction;
0stops.
- startSpeed(speed: int = 100, maxPower: int = 100, useProfile: int = 0) None[source]
Keep turning at
speed(-100..100) until told otherwise.maxPower(0..100) limits how hard it pushes.
- class lpf2.devices.gyroscope[source]
The hub’s built-in gyroscope (
hub.gyro): measures how fast the hub spins, in degrees per second.- getDeviceType() int[source]
A number saying what kind of device this is (see
lpf2.device_type).
- class lpf2.devices.hub_led[source]
A hub’s built-in colored light (
hub.led).- getDeviceType() int[source]
A number saying what kind of device this is (see
lpf2.device_type).
- setColor(r: int, g: int, b: int) None[source]
Set the light to any color by mixing red, green and blue, each 0..255.
setColor(0, 0, 0)is off.
- setColorIdx(color: int) None[source]
Set the light to a named color from
lpf2.color, e.g.hub.led.setColorIdx(color.GREEN).
- class lpf2.devices.port_expander[source]
A Port Expander: plugs into one port and gives you four more.
- getDeviceType() int[source]
A number saying what kind of device this is (see
lpf2.device_type).
- getPort(port_num: int) lpf2.port[source]
One of the expander’s four ports, numbered 0..3 (see
lpf2.port_expander.port_num).It works just like
hub.ports.A.