Skip to main content

Programming with Conditionals - Text-based

Materials Required:
Quantity Materials Needed
1

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

1

VEXcode V5 (latest version, Windows, macOS)

1

Engineering Notebook

1

Clawbot (Drivetrain 2-motor, No Gyro) Template

The Clawbot is ready to make decisions!

During this exploration you can access help right in the VEXcode V5 program.

 

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

Before you begin programming with conditionals, read the VEX Library Article explaining If Then Else Statements. The article can be found here.
For a list of operators to use in the If Then Else statements, read the VEX Library Article explaining Booleans. This article can be found here.

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

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

     

  • Build the project below.

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.

  • Save and download the project as CreatingAStopButton to Slot 1 on the Clawbot, and then run it.

  • For help downloading a project, see the tutorial in VEXcode V5 that explains how to Download and Run a Project(C++ or Python).

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

Step 3: Understanding the wait until() statement.

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() instruction.

Thus, the project needs a waitUntil() instruction that tells the robot to remain stopped until the Brain's screen is released. Otherwise, the forever statement would cause the project to begin again.

The waitUntil() instruction is necessary because of the speed of the project's flow. If it was 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 then statement to an if then else statement.

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

  • If you need help saving a project, click here for Python or for C++.

  • Then build the StopOrDrive project shown below.

  • Download StopOrDrive to Slot 2 on your Clawbot.

  • For help downloading a project, see the tutorial in VEXcode V5 that explains how to Download and Run a Project(C++ or Python).

  • 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 then else statement in the StopOrDrive project.

Using the if then else statement will allow you to add additional buttons to the screen in upcoming activities.