Motor speed changes by increments

Ok so recently I was creating a code for our catapult, however the catapult was going quite fast and I wanted to make it so it started at a certain speed and you could use up or down arrows to change the speed accordingly( say the motor velocity starts at 50, you could press the up button to increase it by 5
and press it again to make the velocity 60 and vise versa. I generally code in python but not the vex code so I am not sure if this code will work, I was wondering if this code would work and if not what I could do to fix it.

x=50
Left_Catapult.set_velocity(x,PERCENT)
Right_Catapult.set_velocity(x,PERCENT)
def controller_Up_Pressed():
    x+=5
controller_1.buttonUp.pressed(controller_Up_Pressed)
def controller_Down_Pressed():
    x-=5
controller_1.buttonDown.pressed(controller_Down_Pressed)
while True:
    controller_1.screen.print("The current catapult velocity is", x)

Thank you

1 Like

That looks good just make sure you put it in a while true loop

don’t put the event registration or handlers in a while loop, but “x” will need to be sent to the motors using either set_velocity or spin at some point. That all depends on what the rest of the code looks like.

2 Likes

can you simplify this please? I’m not sure exactly what it means.

1 Like