Skip to main content

Lesson 3: Driving Until Pressed

Now that you have created a VEXcode VR project to navigate the VR Robot to the letter ‘A’ on the Wall Maze Playground, you will expand your skills using conditionals and sensor values. In this Lesson, you will navigate the VR Robot to the number ‘2’ in the Wall Maze Playground, then explore why additional blocks are needed to drive to the letter ‘B.’ In the mini-challenge, you will apply these skills to navigate from the beginning of the Wall Maze to the number ‘3.’

Wall Maze Playground with the VR Robot in the starting position along the back wall. The number two has a red callout box around it.

Learning Outcomes

  • Identify that a condition always reports a TRUE or FALSE value.
  • Describe the program flow in a project that has a VR Robot drive forward until the Bumper Sensor is pressed.
  • Describe why conditions are used in projects.
  • Identify how to use the Step feature to highlight program execution.
  • Explain why using the Step feature is helpful in troubleshooting and tracing the flow of a project.

Rename the Project

  • If the previous Lesson’s project is not already loaded, load the Unit4Lesson2 project.
  • Rename the project Unit4Lesson3.
VEXcode VR coding environment with a red box at the top middle calling out the project name box. The project name box reads Unit 4 Lesson 3.

Flow of the Project to Drive to the Letter ‘A’

In the previous lesson, the VR Robot drove to the letter ‘A’ on the Wall Maze Playground

Wall Maze Playground with the VR Robot in the starting position along the back wall and the Letter A called out with a red box.
  • To better understand the project flow for driving to the letter ‘A’ on the Wall Maze Playground, begin by modifying your previous project or create a new project to match this base project.

    VEXcode VR project from the previous lesson modified with additional blocks. The project begins with a When started block. The rest of the blocks from top to bottom are Drive forward, Wait until left bumper pressed, turn left for 90 degrees, Drive forward, Wait until left bumper pressed, Turn left for 90 degrees, Drive forward, Wait until Left bumper pressed, Stop driving.

When a project uses a [Wait until] block, the program flow of the project still follows the same top-to-bottom sequence. The [Wait until] block allows the program flow to "pause" at a certain point, until the condition inside of the [Wait until] is met (reports TRUE).

Conditions inside of blocks, such as [Wait until] blocks, allows the user to "control" the program flow. For example, with the [Wait until] block, the program flow will pause and "wait until" the condition is met and reports TRUE, before moving on to the next block.

In this code for driving the VR Robot to the letter ‘A,’ the VR Robot will drive forward until the condition of the Left Bumper being pressed, is TRUE. A condition, such as the Left Bumper being pressed in this example, always reports a TRUE or FALSE value.

VEXcode VR project from this lesson broken apart to show project flow. The When started block is followed by the drive forward block. A gold arrow points downwards from the drive forward block at the Wait until left bumper pressed block. To the right of the block are 2 curved red arrows indicating a circular motion and the words "not pressed (false)" showing what happens when the robot drives forward and the bumper switch is not pressed. Underneath the Wait until block, a green arrow pointing down at the Turn left for 90 degrees block with the words "pressed (true)" indicates that the project will move to that block when the bumper is pressed. Next, a gold arrow points down at the Drive for block and the same sequence repeats. Then, a gold arrow points at a Wait until left bumper pressed block with the same arrows indicated that when the bumper is not pressed the robot will keep driving, and when it is pressed it will move on to the final block in the project, a stop driving block.

For Your Information

The Project Stepping Feature provides you with a visual representation of the flow of the commands as they are being executed within a project. This can provide you with important visual cues when you are trying to troubleshoot or design a VEXcode VR project.

VEXcode VR coding environment with a red box calling out the Step icon and text to the top right of the toolbar.

Drive to the Number '2'

In this Lesson, the project will be edited to have the VR Robot drive to the number ‘2’ on the Wall Maze Playground!

Wall Maze Playground with the robot on the starting position and a red box calling out the number 2.
  • The project from Lesson 2 has the VR Robot turning left to drive to the letter ‘A.’ In order to navigate to the number ‘2,’ the VR Robot will have to turn right instead, drive forward, and then turn left.

    Wall Maze Playground with the VR Robot facing a wall with the letter a to the left. A red arrow points left from the robot towards the letter A. Three green arrows mark the path from the robot to the number 2. The first one points away from the robot to the right. The next points towards the left, and then the final arrow actually points to the left ending at the number 2.
  • Change the direction of the second [Turn for] block to right instead of left.

    Two images of the VEXcode VR project from this lesson indicating changing the second Turn for block from left to right. Both projects have red callout boxes around the second Turn for block. The project on the left has the parameter in the block set to left, and the project on the right has the parameter set to right.
  • Launch the Wall Maze Playground if it is not already open and run the project.
  • Watch the VR Robot begin to drive to the number ‘2,’ but stop at a wall. Thus, the VR Robot needs to turn left once it presses against the wall instead of stopping.

    Image of the Wall Maze playground and the VR Robot stopped facing a wall.
  • Select the “Reset” button to reset the Playground and move the VR Robot back to the starting position.

    Wall Maze Playground with two buttons and a timer on the left. The bottom button has an icon with an arrow pointing in an incomplete circle indicating reset, and is called out with a red box.
  • Edit the code by removing the [Stop driving] block and replacing it with the following commands in order to drive the VR Robot to the number ‘2.’

    Side by side images of the VEXcode project from this lesson. The left project has a Stop driving block at the bottom, and the right project has the Stop driving block removed. It has been replaced by seven blocks which from top to bottom are: Turn left for 90 degrees, Drive forward, Wait until left bumper pressed, Turn left for 90 degrees, Drive forward, Wait until left bumper pressed, Stop driving.
  • Launch the Wall Maze Playground if it is not already open and run the project.
  • Watch the VR Robot drive to the number ‘2’ on the Wall Maze Playground!

    Wall Maze Playground with the VR Robot positioned at the number 2.
  • Select the “Reset” button to reset the Playground and move the VR Robot back to the starting position.

Select the Next button to continue with the rest of this Lesson.