How to write a program to let motor run by press the button on joystick, when button relesed, motor stop working

i’m a new programmer i don’t know hot joystickbutton related with java and motorcontroller.

I would recommend reading the WPILIB docs. https://docs.wpilib.org/en/latest/docs/software/commandbased/binding-commands-to-triggers.html

What I would do is create a command for the button. The command will need to require the subsystem. Then in your robot container, create the joystick object, and set the command to it. You will probably want to use the joystickButtonA.whileHeld(new ShootingCommand());

Also, your command’s initialize method should turn the motor on, and the end method turn it off.

Thanks, it helps a lot. :smile:

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