Audi RS Q e-tron (42160) with the Xbox Controller + lights #2166
-
|
Hello, I managed to program the hub with the demo on pybricks. All works great, but if i try to add lights to PORT.C (since is unused) the controller connects for a second then halts. Any idea how to do this? from pybricks.iodevices import XboxController
from pybricks.parameters import Direction, Port, Button
from pybricks.pupdevices import Motor, Light
from pybricks.robotics import Car
from pybricks.tools import wait
# Set up all devices
steering = Motor(Port.D, Direction.CLOCKWISE)
front = Motor(Port.B, Direction.CLOCKWISE)
rear = Motor(Port.A, Direction.CLOCKWISE)
car = Car(steering, [front, rear])
xbox = XboxController()
light = Light(Port.C)
# Main program
while True:
car.steer(xbox.joystick_left()[0])
car.drive_power(xbox.triggers()[1] - xbox.triggers()[0])
if xbox.button(Button.A):
if light.brightness() == 0:
light.on(100)
else:
light.off()
wait(50) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 10 replies
-
|
Hello, Did you look at the messages on the bottom of the code.pybricks.com screen? Maybe if xbox.button(Button.A):should be if xbox.button.pressed(Button.A):Bert |
Beta Was this translation helpful? Give feedback.
-
|
I only have this at the bottom: Is the same with the modification suggested, controller goes off after 1sec. |
Beta Was this translation helpful? Give feedback.
-
|
Simplified, with this code i get them to light up at start. from pybricks.iodevices import XboxController
from pybricks.parameters import Direction, Port, Button
from pybricks.pupdevices import Light
from pybricks.pupdevices import Motor
from pybricks.robotics import Car
from pybricks.tools import wait
# Initialize the light.
light = Light(Port.C)
# Set up all devices
steering = Motor(Port.D, Direction.CLOCKWISE)
front = Motor(Port.B, Direction.CLOCKWISE)
rear = Motor(Port.A, Direction.CLOCKWISE)
car = Car(steering, [front, rear])
xbox = XboxController()
# Main program
while True:
car.steer(xbox.joystick_left()[0])
car.drive_power(xbox.triggers()[1] - xbox.triggers()[0])
light.on(100)
wait(50) |
Beta Was this translation helpful? Give feedback.

So: progress!
You might add (more or less copied from you original source I had a typo:
xbox.buttonshould bexbox.buttons)Keep the indentation in mind.