Buttons for Separate Functions won't Coexist

Blockquote

Blockquote

We have functions to change the speed of our flywheel mapped to the down button, part of our endgame mapped to B and the other part of endgame mapped to A. For some reason if all 3 are mapped at the same time the speed change won’t work, but if I take out a button for the end game the speed function works again.

Currently we have it so that the entire endgame is mapped to just the A button, with a delay so that we can turn the robot in time to spread the strings out more. We would prefer to have them work on separate buttons though to have more control of our tile spread.

Here is the code for the separate buttons:

void endgameL() {
endgameLeft.spinTo(-60, deg);
wait(0.4, sec);
endgameLeft.stop();
}

void endgameR(){
endgameRight.spinTo(-60, deg);
wait(0.4, sec);
endgameRight.stop();
}

void speed_control() {

speed_set++;
if (speed_set >= 2) speed_set = 0; // If it becomes too large, reset it to 0

switch (speed_set) {

case 0:
  flywheel_speed = slow_speed; 
  break;

case 1:
  flywheel_speed = fast_speed; 
  break;

default:
  flywheel_speed = fast_speed;
  break;

}

}

Controller1.ButtonDown.pressed(speed_control);
Controller1.ButtonB.pressed(endgameL);
Controller1.ButtonA.pressed(endgameR);

Here is the code that we are currently using:
(with the speed control staying the same)

void endgameShoot(){
endgameLeft.spinTo(-60, deg);
wait(2, sec);
endgameRight.spinTo(-60, deg);
}

Controller1.ButtonA.pressed(endgameShoot);

Thank you for any help!

The snippets you showed us don’t have anything that jumps out wrong. Perhaps, you should post the full code. We don’t know, for example, if you set callbacks with the pressed function just once or keep doing that continuously in the loop, exhausting V5 multi-threading resources.

1 Like