Letting go of both buttons will set the motor speed to 0 instantly. Xander Soldaat is a Software Engineer and former Infrastructure Architect. So finally, because we're in that infinite loop, the buttons are checked each run of the loop (which is several times a second)īased on which button is pressed, the motor speed will get set instantly. Else if 7U is not pressed but 7D is pressed then I have 3 conditions, Up is pressed, Down is pressed, neither are pressed. } //Else if ConditionA and Condition B are false, but ConditionC is true then It is a C-based language that offers both traditional text based programming as well as drag-and-drop graphical programming. The other important trick you will may need is you can add as many else ifs as you want. RobotC is the most popular programming language for VEX EDR Cortex and VEX IQ. So if Condition_A was true, the code will not check Condition_B or the catch all. Each run of the if - else if - else chain only runs a single case. Else if none of the above conditions are true then finallyĮach case checks a different value, the lower cases Else IF (Condition B) and else will only run if the previous conditions are false. Else If ConditionA is False, but Condition B is true then Those work like this: //If ConditionA is true then
Now the important trick of this is to use IF - Else IF - and Else Chains. Based on which button is pressed, I set my motors //If Button 7U is pressed then To check each case, I simply check if each button is pressed. I have 3 conditions that I need to cover with this button combination. (I can confirm the concept is right)įor this example, imagine you have one motor and two buttons, one for up, one for down. It's been a bit since I touched RobotC so I can't confirm the code is 100% right but what you're looking for is a simple If - Else If - Else Chain wrapped in an infinite loop.