Toggle a function in pros

I tried making a toggle where in driver control, if you hit R1, it moves the cata to the “heading” of 55 degrees using a rotational sensor, and if you hit R1 again, it’ll move to the “heading” of -55 degrees. My plan was just to toggle between those 2 but when I coded it it just wasn’t doing anything. Does anyone have any ideas or any examples online I can use instead?

I’m not quite sure I understand. Could you send an example of your code?

Could you share code?
Anyway we do something similar with our intake (its not pros thou):

void IntakeBackwards(){
            if (cooldown){ // Cooldown pressed too fast
                return; // Return nothing...
            }
            if (isSpining && isSpiningReverse){ // If isSpining
               /*
                  Since we are alreadying going reverse the user wants us to stop
               */
                Intake.stop(coast); // Stop with coast
                cooldown = true; // Engage cooldown
                isSpining = false; // We are no longer spinning
                wait(300,msec); // Wait for .3 seconds 
                cooldown = false; // Cooldown disabled
            return; // Return to prevent other issues (Avoiding else is a good practice)
            }

            if(isSpining){ // If it is spinning forward the user wants us to spin reverse
              
                cooldown = true; // Cooldown engaged
                isSpiningReverse = true; // We are spinning reverse
              
         Intake.spin(reverse,90,percent); // Spin reverse
           task::sleep(300); // Wait 300 seconds for cooldown
                cooldown = false; // Disable cooldown
            return; // return to prevent the rest of code from running
            }
                //If we are not spinning the user also wants us to start spinning
               cooldown = true; // Engage cooldown
                isSpiningReverse = true; // We are going reverse
                isSpining = true; // We are spinning
                  Intake.spin(reverse,90,percent); // Spin reverse
                task::sleep(300);//Wait 300 seconds for cooldown
      
                cooldown = false; // Disengage cooldown
        }
        void Shoot(){ // Shoot for the other direction
// Same idea
          if(cooldown){
            Controller1.rumble("......_...");
            return;
          }
          if(isSpining && !isSpiningReverse){
                   Intake.stop(coast);
                cooldown = true;
                isSpining = false;
                wait(300,msec);
                cooldown = false;
            return;
          }
          if(isSpining){

                cooldown = true;
                isSpiningReverse = false;
             
         Intake.spin(vex::forward,90,percent);
         task::sleep(300);
                cooldown = false;
          }
           cooldown = true;
                isSpiningReverse = false;
                isSpining = true;
                  Intake.spin(vex::forward,90,percent);
                task::sleep(300);
       
                cooldown = false;
        }

So if you used a bool to track which way the user wants its much easier to code.
This is an example of a toggle.
Seeing your code will be very helpful in fixing your specfic issue.

1 Like

Here is our code:

//bool for Cata Toggle
bool toggleL1 = false;
bool buttonL1Pressed = false;
//bool for Cata
bool buttonL1 = master.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_L1);
 //Cata code
       if(buttonL1 && !buttonL1Pressed){
        buttonL1Pressed = true;
        toggleL1 = !toggleL1;

       }
       else if (!buttonL1){
       buttonL1Pressed = false;
       if(toggleL1){

         Cata.move_relative(109, 100);
       
       int x= Cata.get_position();
       double Modular = x % 360;
       int y= Rotational1.get_position();
       int z= Modular-y;
       while(z > 0.5){
        Cata.move_relative(z, 100);
            x= Cata.get_position();
            Modular = x % 360;
            y= Rotational1.get_position();
            z= Modular-y ;
       }
    
       }
       else if(toggleL1){

        Cata.move_relative(-109, 100);
       
       int x= Cata.get_position();
       double Modular = x % 360;
       int y= Rotational1.get_position();
       int z= y-Modular;
       while(z > 0.5){
        Cata.move_relative(-z, 100);
            x= Cata.get_position();
            double Modular = x % 360;
            y= Rotational1.get_position();
            z= y-Modular ;
       }
      
        
       }
       else{
        Cata.move_velocity(0);
      }