Code Help for Auton Selection

Good Afternoon to you all, I hope every at worlds right now is ready to go. 15800A will be joining you all Saturday. Anyway, my code for my Auton Selection hasn’t been working. here is the code. Ive checked that the limit switch is plugged in properly, and that the Limit Switch is defined correctly in Devices.

Thank you!
Will | 15800A

// Auton selector

  if(AutonSelector.pressing()){
    Brain.Screen.setPenColor(black);
    AutonVar=AutonVar+1.0;
    if(AutonVar>8){
    AutonVar=1;
    }
  }
    
    if(AutonVar==1){ 
    Brain.Screen.setPenColor(black);
    Brain.Screen.setFont(monoL);
    Brain.Screen.setCursor(4,1);
    Brain.Screen.print("NoAuton");  //1

  }
  if(AutonVar==2){
    Brain.Screen.setFont(monoL);
    Brain.Screen.setCursor(4,1);
    Brain.Screen.print("FarSafe");   //2
    
  }
  if(AutonVar==3){
    Brain.Screen.setFont(monoL);
    Brain.Screen.setCursor(4,1);
    Brain.Screen.print("Far Aggressive");   //3
    
  }
  if(AutonVar==4){
    Brain.Screen.setFont(monoL);
    Brain.Screen.setCursor(4,1);
    Brain.Screen.print("Close AWP");   //4

  }
  if(AutonVar==5){
    Brain.Screen.setFont(monoL);
    Brain.Screen.setCursor(4,1);
    Brain.Screen.print("Close Elims");   //5
    
  }
    if(AutonVar==6){
      Brain.Screen.setFont(monoL);
    Brain.Screen.setCursor(4,1);
    Brain.Screen.print("Close Safe");   //6

  }
      if(AutonVar==7){
        Brain.Screen.setFont(monoL);
    Brain.Screen.setCursor(4,1);
    Brain.Screen.print("Skills");   //7
    
  }
     if(AutonVar==8){
       Brain.Screen.setFont(monoL);
    Brain.Screen.setCursor(4,1);
    Brain.Screen.print("MotorTest");   //8
  }
  
    /////////////
1 Like

What is the brain screen printing? Where is this code located? It’s possible you’re pressing it too fast and it’s triggering multiple times. Maybe try switching to a callback or using a wait in the loop.

You need to put the code where you are actually pressing the switch in a forever loop (while (1)), and the actual selector need to be in the automatic portion. The switch part needs to be in pre auton. You also need it to be in an if/else statement. This is for C++, and I don’t know about python

1 Like

The brain screen will print the name of the auton that I have selected as the initial value of the AutonVar. It prints into the right spot as well, but not in the right color, it shows as pink just like the background. If I was clicking it too fast and it changed to a different auton that would show atleast a change because the odds it lands back on the default auton are low. What do you mean a callback?

A function callback sets a function to be called when something happens (like a limit switch being pressed)
For example

void limitSwitchPressed(){
auton++;
if(auton>8)
auton = 1;
}

int main(){
limitswitch.pressed(limitSwitchPressed);
// Other competition stuff
}

This codes sets limitSwitchPressed to be called whebt he limit switch is pressed. Additionally I recommend putting if statements for checking the auton number inside a while(true) so they are constantly being rechecked.

2 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.