How do I make a single brushless motor go one way and then the other with buttons

You can drive it in reverse. That likely means calling the set() function with a negative number.

I’m using a joystick I’ve tried that and it doesn’t work

(This is more of a programming question than a motor one, so updating the thread category would be nice, as would a thread titled along the lines of “controlling motor direction with a digital input (button)”)

There are generally a lot of older threads where people ask questions like this. Worth using the search function for quicker answers than waiting for people to respond.

It has been a long time (2015) since I have touched robot code, so I am going to speak in broad strokes.

Are you asking for how you would go about running a motor forward with a button while it is pressed and backwards with a different button while it is pressed?

Or are you asking how to run a motor forward for 2 seconds then reverse it for another two seconds when holding a button?

1 Like
bool m_toggle = false; //put this in Robot.h
frc::XboxController m_stick{0}; //Also in Robot.h
//Motor init not shown
if (my_stick.GetXButtonPressed)
if (toggle)
toggle = false;
toggle = true;

This is a very basic example of doing that in C++

Yes. I figured you it how to make a single motor go forward and reverse now I need to know how to do it while holding a button. So it the motor will run while I’m holding the button.

You can do that with some simple code, here is an example below (written in Java):

    } else if (driverGamepad.getBButton()){
    } else {

Thank you I’ll test it out because i usually used

If (getRawButtonPressed(button 1))
Do something;

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.