Auton Selector Help (C++)

I am trying to make an auton selector and have the buttons set up, but how do I code it to where it selects and autonomous to run based on which button is pressed. Also, if you’re going to reply please tell me what the code actually does and explain it. I know how to code, but I can’t understand heavy complicated code.

(And yes I have looked at other posts)

perhaps post the code you already have.

Have you looked at this one ?

This is the code I have currently.

  vex::color re (165,44,46);
  Brain.Screen.setFillColor(re);
  Brain.Screen.setFont(monoM);
  Brain.Screen.drawRectangle(0,0,240,120);
  Brain.Screen.setCursor(3,3);
  Brain.Screen.print("Right Side Long Goal");
  // TR Blue Selection
  vex::color blu (38,108,165);
  Brain.Screen.setFillColor(blu);
  Brain.Screen.drawRectangle(240,0,240,120);
  Brain.Screen.setCursor(3,26);
  Brain.Screen.print("Right Side Center Goal");
  // BL Green Selection
  vex::color gre (57,168,64);
  Brain.Screen.setFillColor(gre);
  Brain.Screen.drawRectangle(0,120,240,120);
  Brain.Screen.setCursor(9,3);
  Brain.Screen.print("Left Side Long Goal");
  // BR Yellow Selection
  vex::color yell (229,201,61);
  Brain.Screen.setFillColor(yell);
  Brain.Screen.drawRectangle(240,120,240,120);
  Brain.Screen.setCursor(9,27);
  Brain.Screen.print("Left Side Center Goal");
  
  waitUntil(Brain.Screen.pressing());
  if (Brain.Screen.xPosition() < 240.0) {
    if (Brain.Screen.yPosition() < 120.0 ){

    Brain.Screen.setFillColor(re);
    Brain.Screen.drawRectangle(0,0,480,240);
    Brain.Screen.setCursor(3,7);
    Brain.Screen.setFont(monoL);
    Brain.Screen.print("Right Side Long Goal");
    Brain.Screen.setCursor(4,7);
    Brain.Screen.print("     SELECTED");
    wait(2,seconds);
    Brain.Screen.clearScreen();
  }
  else {
    Brain.Screen.setFillColor(gre);
    Brain.Screen.drawRectangle(0,0,480,240);
        Brain.Screen.setCursor(3,7);
    Brain.Screen.setFont(monoL);
    Brain.Screen.print("Left Side Long Goal");
    Brain.Screen.setCursor(4,7);
    Brain.Screen.print("     SELECTED");
    wait(2,seconds);
    Brain.Screen.clearScreen();
  }}
  

  else {
    if (Brain.Screen.yPosition() < 120.0 ){
    Brain.Screen.setFillColor(blu);
    Brain.Screen.drawRectangle(0,0,480,240);
    Brain.Screen.setCursor(3,7);
    Brain.Screen.setFont(monoL);
    Brain.Screen.print("Right Side Center Goal");
    Brain.Screen.setCursor(4,7);
    Brain.Screen.print("      SELECTED");
    wait(2,seconds);
    Brain.Screen.clearScreen();
  }
  else {
    Brain.Screen.setFillColor(yell);
    Brain.Screen.drawRectangle(0,0,480,240);
    Brain.Screen.drawRectangle(0,0,480,240);
    Brain.Screen.setCursor(3,7);
    Brain.Screen.setFont(monoL);
    Brain.Screen.print("Left Side Center Goal");
    Brain.Screen.setCursor(4,7);
    Brain.Screen.print("      SELECTED");
    Brain.Screen.setFillColor(black);
    Brain.Screen.drawRectangle(3,7,10,2);
    wait(2,seconds);
    Brain.Screen.clearScreen();
  }}

  }

(im still working on it so the end is a bit messy)

I have tried understanding the pdf attached to the post but I do not understand how to put that into my code.

Everything from typedef struct _button to the end of void displayButtonControls goes in the head of your code where things are defined. That code defines the buttons visually and sets a bool for each button. Those bools can then referenced in the autonomous section to make selections (the pdf gives some examples.)

There is also a few lines of code inside int main that starts the brain registering events for the button presses.

You may need to look up struct and callback functions to better understand how the code works.

A couple things, first off there is no void displayButtonControls, at least not that I see. Also, when I put in buttons where it says bool _____ = buttons [_].state; I get a problem for buttons. I’ve even tried opening the file in the post with the pdf but it does not open properly.

As noted in the original topic for our Autonomous selector, it was developed using VEX Coding Studio (now defunct). You can load it using VEXcode Pro V5 by using the import function. I just tried it, it still works.

If this is all too daunting, then it may be best to develop your own version that is at your skill level. I know our 7th grade team developed their own using Blocks as they were not comfortable with C++ or complex data structures in the language. Remember, the robot must reflect the skill level of the team.

The actual code is in the .vex file. The IDE that opens that format is available but no longer supported.

For a file that can be opened at codeV5.vex.com I have modified the code posted in 2019 to remove helper code and simplify the auton example. Do understand you can use the button booleans in a wide variety of ways … you could just have each button be a specific set of code to have 8 options, or you could have each button choice refine options (as the example code shows) to get many more than 8 autonomusseez.

WalshBot-Buttons-Updated.zip (3.5 KB) (would not allow upload of .V5cpp)

Pascal, if you want this taken down feel free to poke a moderator – not looking to step on toes.

Nope - it is the right amount of help to move problem solution forward.