Hi,
I'm trying to control a DC motor with an Xbox controller, using the controller to control speed and direction of the motor.
I have the Xbox bit sorted, in that it outputs a value of between -1 and 1 on each axis.
I have also got the controller to drive the motor forward proportionately by using gpiozero and robot.forward(value)
The question is whether it is possible to use the notation of the value to determine whether the motor goes forward or backward,
ie if the value is >0 run forward, if it is less than 0 run backward.
I realise I could use an 'if' statement, but that is going to get cluttered very quickly when I want to run 4 motors.
Is there a more efficient method?
Thanks
CJ
I'm trying to control a DC motor with an Xbox controller, using the controller to control speed and direction of the motor.
I have the Xbox bit sorted, in that it outputs a value of between -1 and 1 on each axis.
I have also got the controller to drive the motor forward proportionately by using gpiozero and robot.forward(value)
The question is whether it is possible to use the notation of the value to determine whether the motor goes forward or backward,
ie if the value is >0 run forward, if it is less than 0 run backward.
I realise I could use an 'if' statement, but that is going to get cluttered very quickly when I want to run 4 motors.
Is there a more efficient method?
Thanks
CJ
Statistics: Posted by Candyjet — Sat Jan 03, 2026 10:24 am — Replies 5 — Views 105