Tilt Sensor

../_images/pupdevice-tilt.png

../_images/pybricks_variables_set_tilt_sensor.svg

class TiltSensor(port)

LEGO® Powered Up Tilt Sensor.

Parameters:

port (Port) – Port to which the sensor is connected.

../_images/pybricks_blockTilt_TiltSensor_imu.tilt.pitch.svg

../_images/pybricks_blockTilt_TiltSensor_imu.tilt.roll.svg

awaittilt() Tuple[int, int]: deg

Measures the tilt relative to the horizontal plane.

Returns:

Tuple of pitch and roll angles.

Examples

Measuring pitch and roll

from pybricks.pupdevices import TiltSensor
from pybricks.parameters import Port
from pybricks.tools import wait

# Initialize the sensor.
accel = TiltSensor(Port.A)

while True:
    # Read the tilt angles relative to the horizontal plane.
    pitch, roll = accel.tilt()

    # Print the values
    print("Pitch:", pitch, "Roll:", roll)

    # Wait some time so we can read what is printed.
    wait(100)