Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 6970

Automation, sensing and robotics • Control direction of motor with a value

$
0
0
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

Statistics: Posted by Candyjet — Sat Jan 03, 2026 10:24 am — Replies 5 — Views 105



Viewing all articles
Browse latest Browse all 6970

Trending Articles