How to have a motor toggle on and off in PROS for Vex LEGACY Cortex

I would like to know how to toggle a motor on and off on my controller. Basically I want my intake with a press of a button to turn on and then to press it again turns it off… I don’t want to have to keep on holding the button to have it turning and I don’t want it to turn it on from the start when the battery is plugged in either (i want to conserve battery power I’d rather have a button that controls it being toggled on or off)… This obviously requires code, so if someone could help me out on how to make that happen (in code) in PROS that would be great. Please be reminded I’m using a Vex Legacy Cortex
Thanks for your time! I really appreciate it!

It just needs to be in C++ code in think

No, it doesn’t need to be in C++. We coded all our Cortex stuff in PROS using C. It can be done in C++, though.

Here is the trick: you want to know when the button is released so you can distinguish between a new press and a button that has been pressed but not yet released.

Here is a quick example I just threw together:

bool motorOn = false;
bool buttonHeld = false;

while(true) {
   if(joystickGetDigital(1,5,JOY_UP) { // choose the appropriate button on the appropriate controller
      if(!buttonHeld) { // only do this swap if this is a new button press
         buttonHeld = true; // remember that the button is held down so we have to wait for a release
         motorOn = !motorOn; // toggle the state for the motor
         if(motorOn) { // if the motor should now be on, turn in on
            motorSet(1,100) // choose the appropriate port and speed
         }
         else { // if the motor should now be off, turn in off
            motorSet(1,0) // choose the appropriate port
         }
      }
   }
   else {
      buttonHeld = false; // the button is not being held down, so the next time it is detected is a new press
   }
   delay(10);
}

@callen

In PROS we made some adjustments but this is the code… there are no errors in PROS, but this program is not being downloaded into the brain. What might be the problem?

void operatorControl() {
bool motorOn = false;
bool buttonHeld = false;

while(true) {

if(joystickGetDigital(1,5,JOY_UP)) { // choose the appropriate button on the appropriate controller
if(!buttonHeld) { // only do this swap if this is a new button press
buttonHeld = true; // remember that the button is held down so we have to wait for a release
motorOn = !motorOn; // toggle the state for the motor
if(motorOn) { // if the motor should now be on, turn in on
motorSet(1,100); // choose the appropriate port and speed
}
else { // if the motor should now be off, turn in off
motorSet(1,0); // choose the appropriate port
}
}
}
else {
buttonHeld = false; // the button is not being held down, so the next time it is detected is a new press
}
delay(10);
}
}

Yes I am aware the indenting is off, but it is correct on my IDE just when i copied and pasted it to the web browser i mistakenly messed it up… so dont worry about the indentation

The exact error code is
No binary was found! Ensure you are in a built PROS project (run make) or specify the file with the -f
flag

I replied in the other thread where you asked the same thing. I don’t remember which approach creates that error for sure. I think it’s when you try to upload but haven’t made the file. We used make-upload so we were doing the two together.