This is my code and I am having trouble with this code the up and down goes indefinitely instead of going to the else because of the while and other times it freezes I tried adding sleeps to make it not skip any lines but it still skips the else
What it is supposed to do is when you press the up arrow it goes up until you let go and the same with the down arrow
Please format your code with triple backticks on either side of the code. Makes it easier to read for everyone else, and to help you. ``` ← these are triple backticks
Please write what this code is meant to do. That way, we can help find problems.
You are basically saying
While event x is happening,
if it is actually happening, do output 1 (spin the arm)
if it is not actually being pressed, stop the arm
The only way the arm would be stopped would be if you stopped pressing the button in 10 milliseconds, so at the start, write if (Controller1.ButtonUp.pressing()){while(true){[insert code here]}}
Or, just add a waituntil
Like
vex::task::sleep(10);
armMotor.spin(forward);
vex::task::sleep(10);
waitUntil(!Controller1.ButtonUp.pressing());
armMotor.stop();
}
if(Controller1.ButtonDown.pressing()){
vex::task::sleep(10);
armMotor.spin(reverse);
vex::task::sleep(10);
waitUntil(!Controller1.ButtonDown.pressing());
armMotor.stop();
} ```
Also, they are not apostrophes, they are back ticks (` not ')
Your while loop exits before the else can ever run, because they are checking for the same thing. If you want it to go on forever you can replace the Controller1.ButtonUp.pressing() in the while with true to make it go on forever. If you then want the loop to stop you can add a break after stoping the motors inside the else statement.
Also, make sure you don’t call Controller1.ButtonUp.pressed(insertnameoffunction); multiple times in the loop. Just call it once at the beginning of the program and then function insertnameoffunction will be called (back) by vexos whenever button is pressed, and only once per press, which is nice.