How do I start and stop a motor at the press of a button

How do I code a program on Vexcode Pro V5 that causes a motor to start turning when I press a button and to stop spinning when I press it again.

I have a basic Idea of how to do it, but I do not know how to write it.

If Button a is pressed and value is 0
set value to 1

If button a is pressed and value is 1, set value to 0’

If value of Button a == 1

make the motor spin

If value of Button a==0


I want to use the code for an intake that starts and stops so that my team would not have to hold the button while going around the field

if button is pressed {

   if  intake is on {
      turn it off
  } else {
      turn it on


Think you’ve got it from here with this pseudocode?

1 Like

That won’t quite work. The intake will constantly quickly switching between the two, because the drive loop is repeating so quickly.

What OP needs to use is a rising-edge circuit. This will make the intake only switch states once when the button is pressed.

Here is a little scratch project I made demonstrating this concept:

Have fun progaming!


Could be wrong since I don’t use vexcode, but I’m pretty sure there’s a button param called pressed that runs the callback only once immediately when the button is pressed.