Skip to main content

The Clawbot is ready to make decisions!

This exploration will give you the tools to be able to start creating some cool projects that use if-else statement.s

  • VEXcode V5 Python commands that will be used in this exploration: 
    • drivetrain.drive_for(FORWARD)
    • brain.screen.pressing()
    • drivetrain.stop()
    • if condition:
    • else:
    • while True:  
    • wait(5, SECONDS)

You can use the Help information inside of VEXcode V5 to learn about the Python commands.

Image of the Help in VEXcode V5 open in a Python project window

Make sure you have the hardware required, your engineering notebook, and VEXcode V5 ready.

Materials Required:
Quantity Materials Needed

VEX V5 Classroom Starter Kit (with up-to-date firmware)


VEXcode V5 (latest version, Windows, macOS)


Engineering Notebook


Clawbot (Drivetrain 2-motor, No Gyro) Template

Step 1: Let's start with an understanding of conditional statements 

Before you begin programming with conditionals, read the article explaining if-else statements. The article can be found here (Google Doc / .docx / .pdf).
Image of the start of the Using if-else statements in VEXcode V5 Python article
For a list of operators to use in the if-else statements, read the article explaining Booleans. This article can be found here (Google Doc/.docx/.pdf).

Image of the start of the Using Booleans article

Step 2: Let's start programming with conditional statements.

  • Open the Clawbot (Drivetrain 2-motor, No Gyro) template example project.


  • Build the project below.

Image of a VEXcode V5 Python project with an if statement in it

Do the following in your engineering notebook:

  • Explain what the project has the Clawbot do. You will need to explain more than the fact that it creates a stop button. Explain which instructions make the Clawbot do what.

  • Write a one sentence summary that captures what the project does.

  • Test to see if your prediction of what the project has the Clawbot do is correct.

  • Name the project CreatingAStopButton. Download and run the project on the Clawbot.

  • Check your explanations of the project, and add notes to correct them as needed.

Step 3: Understanding the while and wait() statements.

Notice that if the Brain's screen is pressed, the flow of the project moves quickly and the project will move to the next instruction, which is the drivetrain.stop() command.

Thus, the project needs the while and wait commands that tell the robot to remain stopped until the Brain's screen is released. Otherwise, the forever statement would cause the project to begin again.

Image of the the while brain screen is pressed command with a wait command in a VEXcode V5 Python project

The while and wait commands are necessary because of the speed of the project's flow. If they were not there, the project would move to the next instruction before the robot ever had time to respond.

Step 4: Change the project.

Our next step is changing the if statement to an if-else statement.

  • Start by saving CreatingAStopButton as the new project, StopOrDrive.

  • If you need help saving a project, view these articles.

  • Then build the StopOrDrive project shown below.

Image of the Stop or Drive example project in VEXcode V5 Python

  • Download StopOrDrive to Slot 2 on your Clawbot.

  • For help downloading and running a project, see this article.

  • Test CreatingAStopButton (Slot 1) and then test StopOrDrive (Slot 2) and compare them to see if there are any difference in the robot's behavior. Note any differences in your engineering notebook

The two projects have the Clawbot behave the same way. The only difference is the use of the if-else statement in the StopOrDrive project.
Using the if-else statement will allow you to add additional buttons to the screen in upcoming activities.