Skip to main content
Teacher Portal

Programming with Conditionals in VEXcode IQ

Teacher Toolbox icon Teacher Toolbox - The Purpose of this Activity

Programming with conditionals can be accomplished by using an [If then] block within a project.

VEXcode IQ If then block from the Toolbox

This activity will introduce students to programming with an [If then] block as well as using sensing and operator blocks to have the robot check if the Brain Up button is pressed. If it is pressed, the Clawbot's arm will raise. This first introduction will lay the ground work for adding robot reactions to other buttons on the brain.

For more information about the [If then], [Brain button pressed], [Wait until] or the <not> blocks, visit the help information within VEXcode IQ. For more information about this built in help tool, click here.

The following is an outline of what your students will do in this activity:

  • Watch the Using Loops and If-Then-Else Blocks tutorial videos.
  • Use the Clawbot (Drivetrain) template to build the ArmUp project provided and predict what the project does.
  • View a flowchart to help explain the flow of the blocks in the project.
  • Refine their explanations of what the ArmUp project does.
  • Edit their project by adding a [Wait until] block.
  • Stop and Discuss: Students will reflect on their predictions on what the project will have the Clawbot do compared to their actual observations.
Materials Required:
Quantity Materials Needed
1

VEX IQ Super Kit

1

VEXcode IQ

1

Engineering Notebook

1

Clawbot (Drivetrain) Template

Teacher Toolbox icon Teacher Toolbox

For suggestions on teaching strategies for this section, review the Delivery column of the To Do, or Not to Do Pacing Guide (Google / .docx / .pdf).

The Clawbot is ready to make decisions!

This activity will give you the tools to program your robot with conditional behaviors.
The [If then] block is the main focus within the activity but other Sensing, Control, and Operator blocks are also used.

Example blocks from the VEXcode IQ Toolbox - Brain button pressed, If then, not operator block, and wait until block.

You can use the Help information inside of VEXcode IQ to learn about the blocks. For guidance in using the Help feature, see the Using Help tutorial.

VEXcode IQ Toolbar with the Tutorials icon called out in a red box, to the right of the File menu.

Teacher Tips icon Teacher Tips

If this is the student's first time using VEXcode IQ, they can also see the Tutorials in the toolbar to learn other basic skills.

VEXcode IQ Toolbar with the Tutorials icon called out in a red box, to the right of the File menu.

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

Before you begin programming with conditionals, first watch the Using Loops and If-Then-Else tutorial videos in VEXcode IQ.

Start by watching the Using Loops Tutorial video in VEXcode IQ.

Tutorial icon reads Using loops at the bottom and shows an outline of blocks within a loop.

Then watch the If-Then-Else Tutorial video in VEXcode IQ.

Tutorial icon reads If then else blocks at the bottom and shows the outline of if then else block with arrows.

Step 2: Programming with conditionals.

We want to build a project that will raise the arm if the condition of the Brain Up button being pressed is true.
 VEX IQ Brain with the Up button beside the upper left corner of the screen called out with a red box.
If the condition is false, the Arm Motor will stop. Let's explore building a project that uses a [Forever] block and the [If then] conditional block to program the arm.

  • Open the Clawbot (Drivetrain) Template. For help, view the Using Example Projects and Templates tutorial video.
    Example project icon reads Clawbot Drivetrain, to indicate which template to choose for this activity.
  • Build the project below.
    VEXcode IQ project with a when started block with a forever block attached. Inside the Forever block is an If then block that reads If Brain Up button pressed then spin arm motor up. Next is a stop arm motor block.
  • Save the project as ArmUp. If students need help saving the project, refer to the Naming and Saving tutorial video in VEXcode IQ.
    Project name dialog box in the VEXcode IQ Toolbar. Slot 1 is selected and the project name reads Arm Up.
  • Check to make sure the project name ArmUp is now in the window in the center of the toolbar.
  • Predict what the project will have the Clawbot do in your engineering notebook. Explain both the user's and the Clawbot's behaviors.
  • Test to see if your prediction of what the project has the Clawbot do is correct.
    • Download the project to Slot 1 on the Clawbot, and then run it.
    • For help downloading and running a project, see the tutorial in VEXcode IQ that explains how to Download and Run a Project.
      Tutorial icon reads Download and run a project at the bottom and has a download icon and triangle above.
  • Check your explanations of the project and add notes to correct them as needed.

Teacher Toolbox icon Teacher Toolbox

The project that the students build above will not work as-is. A [Wait until] block is necessary because of the speed of the project's flow. If it was not there, the project will move to the next block before the Arm Motor ever has time to respond. Thus, the blocks will flow down to the [Stop motor] block and then start back at the top of the stack because of the [Forever] block that repeats all blocks contained inside of it. This will be explored and then explained to the students in the next step.

Teacher Toolbox icon Teacher Toolbox - Stop and Discuss

Now that the students have tested the project, ask them how their predictions compared to their observations. Facilitate the discussion by asking the following questions:

  • Was your prediction the same as your observation?

  • What seems to be happening in the project?

  • Is the condition of the Up button being pressed only checked once?

  • What do you think needs to be added to the project for it to work properly?

Step 3: Understanding the [Wait until] block.

In the previous step, the project did not raise the arm successfully. View the following flowchart that explains the project flow. Notice that if the Brain Up button is pressed, the flow of the project moves so quickly that the project will move to the next block, which is the [Stop motor] block.

Project flow image indicating how the project is executed to make a decision. "If brain up button pressed' is labeled a the Condition. If pressed (true) then an arrow indicated spin arm motor up. If not pressed, false, a red arrow indicates stop arm motor. All of this is repeated because it is within the forever loop.

Thus, the project needs a [Wait until] block that tells the Arm Motor to keep spinning until the Brain Up button is released.

VEXcode IQ wait until block with the condition set to not Brain up button pressed, by nesting the Brain Up button pressed block inside a not operator block.

The [Wait until] block is necessary because of the speed of the project's flow. If it was not there, the project would move to the next block before the Arm Motor ever had time to respond. Thus, the blocks would flow down to the [Stop motor] block and then start back at the top of the stack because of the [Forever] block that repeats all blocks contained inside of it.

Let's explore changing the project by adding a [Wait until] block. The Arm Motor will now continue to spin until the Brain Up button is released. Once the Brain Up button is released, the project will continue to the next block, which is the [Stop motor] block.

The project will now first check the condition if the Brain Up button is being pressed. If the Brain Up button is being pressed (TRUE), then the arm will spin up until the Brain Up button is released. Once the Brain Up button is released, the project will move to the [Stop motor] block before returning to the top of the stack to begin again because of the [Forever] block.

If the Brain Up button is not pressed (FALSE), then the project will move to the [stop motor] block before returning to the top of the stack to begin again because of the [Forever] block and the arm will never spin.

Project flow image indicating how the project is executed to make a decision. "If brain up button pressed" is labeled as the condition. If pressed, true, then a green arrow indicates the spin arm motor up block will run followed by the wait until not brain up button pressed block reports true, then the stop arm motor block will run. If the brain up button is not pressed, it's false, and a red line indicates the project moves directly to stop arm motor. Again all of this is continually repeated inside the forever loop.

Motivate Discussion icon Motivate Discussion

Q: When the wait until block is not used, what happens once the Brain Up button is pressed?
A: Because of the speed of the project flow, the project moves from the [Spin] block to the [Stop motor] block faster than the Arm Motor can respond. Thus, the arm does not move.

Q: What is the purpose of the wait until block in the project above?
A: The wait until block allows the arm to continue spinning up until the Brain Up button is released.

Q: What is the progression of the project flow if the condition of the Brain Up button being pressed is FALSE (released)?
A: If the condition is false, the project flow will continue to the [Stop motor] block before returning to the top of the stack repeating forever.

Step 4: Adding the [Wait until] block.

Let's add the [Wait until] block:

  • Add the [Wait until] block to your ArmUp project so that your project looks like the following:

    VEXcode IQ project with a when started block and a forever block attached. Inside the Forever block is an If then block that reads If brain up button pressed then spin arm motor up, wait until not Brain up button pressed. Beneath the if then block is a stop arm motor block.

  • Save the project as ArmUp2. If students need help saving the project, refer to the Naming and Saving tutorial.

 

Project name dialog box in the VEXcode IQ Toolbar. Slot 2 is selected and the project name reads Arm Up 2.

  • Download the project to Slot 2 on the Clawbot, and then run it.
  •  
  • For help downloading and running a project, see the tutorial in VEXcode IQ that explains how to Download and Run a Project.
    Tutorial icon that reads Download and Run a project on the bottom.
  • Test to see if the arm will now spin up when the Brain Up button is pressed.
  • Verify that when the Brain Up button is not pressed (released) that the Arm Motor stops.
  • Write your observations of how the Clawbot behaved before and after adding the [Wait until] block to your project in your engineering notebook.

Teacher Toolbox icon Teacher Toolbox - Stop and Discuss

After students have tested the project before and and after adding the wait until block, discuss with students how this allows the arm to continue spinning until the Brain Up button is released. Ask students to share their observations from their engineering notebooks. Facilitate a discussion by asking the following questions:

  • Did you think that the project would work the first time before adding the wait until block?

  • How did testing the first project allow you to recognize that there was something wrong with the it?

  • Is the Brain Up button condition only checked once in the project?

Students' engineering notebooks can be maintained and scored individually (Google / .docx / .pdf) or as a team (Google / .docx / .pdf). The previous links provide a different rubric for each approach. Whenever a rubric is included in educational planning, it is good practice to explain the rubric or at least give copies to students before the activity begins.