Help! Plz I'm New

I am trying to change the default drive controls. I want to change it so that when I press the “A” button, the robot moves forward. Here’s the catch, I want to make it so that as long as I hold the “A” button, the robot will keep moving forward. When I let go of the “A” button, I want the robot to stop.

Here’s the code:

vexcode_brain_precision = 0
vexcode_controller_1_precision = 0
remote_control_code_enabled = None
myVariable = 0

def when_started1():
    global myVariable, vexcode_brain_precision, vexcode_controller_1_precision, remote_control_code_enabled
    brain.screen.print("VEXcode")
    remote_control_code_enabled = True
    motor_1.set_velocity(50, PERCENT)
    motor_3.set_velocity(50, PERCENT)
    motor_8.set_velocity(50, PERCENT)
    motor_10.set_velocity(50, PERCENT)

def onevent_controller_1buttonA_pressed_0():
    global myVariable, vexcode_brain_precision, vexcode_controller_1_precision, remote_control_code_enabled
    while not controller_1.buttonB.pressing():
        motor_1.spin(FORWARD)
        motor_10.spin(REVERSE)
        wait(5, MSEC)

# system event handlers
controller_1.buttonA.pressed(onevent_controller_1buttonA_pressed_0)
# add 15ms delay to make sure events are registered correctly.
wait(15, MSEC)

when_started1()

edit by mods to add code tags.

you can put it in an if/else loop so that
if the button is pressing(
go forward)
else(
make motors stop)

1 Like

Hi @Kirbs. I think you’re overcomplicating it a bit. This should work

while(true){
      if(Controller1.buttonA.pressing() == true){
           Rightmotor.spin(forward);
           Leftmotor.spin(forward);
      }
      else{
           Rightmotor.stop(brake);
           Leftmotor.stop(brake);
        }
}
6 Likes

Dang someone tryna steal my name. Of course it’s someone from Ohio :rage:

3 Likes

Thank you for your help

1 Like

Thanks but can I get the code in block format? plz

I have never used VEXcode blocks, but that shouldn’t be too hard to copy into blocks.

image

3 Likes

Thank youuuu so muchhhhhhhh