I’ve been trying to get this program to work but I honestly don’t know what I’m doing. The idea is that this motor moves on its own until you hold A, but when you release button A, it starts up again. I’m not entirely sure if I’m going at this problem head-on or what though. Don’t worry about the comments, they mean nothing, I only used an example to know what I was doing.
The first thing I noticed in your code was that your loop runs only so long the left button is being held down from the moment the code is started. If at any moment you let go your code ends. I’m going to have to assume that you don’t want that - that while statement can just be
While(true){
}
Next, one option you have is to just check if the a button is pressing. If it isn’t, turn on the motor.
Here’s an excerpt from some of my old code, the logic is a bit reversed for you, but this is the idea:
// Arm Control
// Use L1 and L2 buttons for directional actuation, if no button is pressed, turn off motor
if (Controller1.ButtonL1.pressing()) {
ArmMotor.spin(directionType::fwd, 100, velocityUnits::pct);
}
else if (Controller1.ButtonL2.pressing()) {
ArmMotor.spin(directionType::fwd, -100, velocityUnits::pct);
}
else {
ArmMotor.stop();
}