When you connect the Xbox Controller to your LEGO Technic hub or LEGO Spike hub, you can read the buttons and analog inputs, but also control the builtin rumble actuators.

This lets you create haptic feedback, which can be great for immersive remote control driving!

In this example, we used the rumble block to make the controller vibrate when the motor experiences load.

You can make the Xbox Controller rumble to create force feedback.
You can make the Xbox Controller rumble to create force feedback.

Controlling the actuators separately

The Xbox Controller has 4 builtin actuators. There is a big and a small one in the main handles, and two smaller ones behind the triggers.

If you give a single power value, the left and right main actuators will both rumble with that power. For more fine-grained control, set power as a list of four values: this controls the left main actuator, right main actuator, left trigger actuator, and the right trigger actuator, respectively.

For example, (50, 0, 100, 0) makes the left main actuator run at half power and the left trigger at full power:

You can also adjust the duration and the number of times the rumble repeats:

You can find more details in the documentation.

Running it as a Python program

You can also run this project as a Python (MicroPython) program. The following code was generated from the block program above. To run it, create a new empty Python program in Pybricks and copy the code into it.

from pybricks.iodevices import XboxController
from pybricks.parameters import Direction, Port, Stop
from pybricks.pupdevices import Motor
from pybricks.tools import wait

# Set up all devices.
motor = Motor(Port.A, Direction.CLOCKWISE)
controller = XboxController()


# The main program starts here.
motor.run(300)
while True:
    # Rumble the controller if the motor experiences load.

    # That's force feedback!
    if abs(motor.load()) >= 50:
        controller.rumble(100, 200)
    wait(200)
Python representation of the block program.