Making Servos Stay in Place

A few rookie teams were asking how to make a servo move to a specific place at the click of a button. I thought I would post how I usually do this. Here some some that will make the servo move to 100 and stay there when button 6U is pressed, and move to to 20 and stay there when button 6D is pressed.


task main(){
  int upperLimit = 100;
  int lowerLimit = 20;
  bool isUp = false;
  
  while(true){
    isUp = vexRT[Btn6U] ? 10 : vexRT[Btn6D] ? 0 : isUp;
    servo[arm] = isUp ? upperLimit : lowerLimit;
  }
}  

Nested Trinaries, very nice. Can you do it in one line like this?
servo[arm] = val = (b1 ? hival : b2 ? lowval : val);
Note that trinaries are std C, and work in EasyC as well as Robot C.

people_in_the_world = understand_binary ? kind_1 : kind_0;

Yes, I personally do it in 1 line, but I thought that this would be easier to understand for beginner programmers.

hi im a rookie programmer, and we use mplab for our vex robots, how could i translate this code to mplab, assuming that i use the starter vex code?