Skip to main content
Materials Required:
Quantity Materials Needed
1

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

1

VEXcode V5 (latest version, Windows, macOS, Chromebook)

1

Engineering Notebook

1

StopOrDrive project from the previous Play page

The brain's screen can have more than one button.

This activity will let you program the robot to drive forward and turn left or right depending on which side of the brain's screen is pressed.

The three additional types of blocks that you will need during this activity are the following:

VEXcode V5 Blocks from the toolbox - a Turn block set to right; a less than operator; and a screen position set to x.

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

VEXcode V5 Toolbar with a red arrow pointing to the Tutorials icon. The Tutorials are to the far right after the V5 logo, a globe icon, and FIle.

 

Step 1: Let's start by reviewing the StopOrDrive project.

The StopOrDrive project had the Clawbot stop if the screen was pressed, or else it had it drive forward.
The entire screen was one big button but in this next project, we want half the screen to be one button and the other half to be the other.

Stop or Drive project from the previous lesson. The project begins with a when started block with an attached Forever block. Inside the forever block is an if then else block that reads if screen pressed then stop driving; wait until not screen pressed. Else, drive forward.

In order to split the screen into two buttons, we need to understand more about the layout of the screen.

Pixel grid of the V5 Brain screen shows 12 numbered rows along the lefthand side, with the top row labeled Row 1 and the bottom labeled Row 12. Across the top are 48 numbered columns, with Column 1 labeled on the far left and Column 48 labeled on the far right. The total pixel measurements are 480px wide by 240 px tall.

  • Notice that the columns increase in number from left to right. The number of columns is 48 and the screen is 480 pixels wide.
  • Write down in your engineering notebook that the x-value on the screen is equal to the number of pixels measured from left to right.
  • What is the x-value of the center of the screen? For this activity, you can focus on the x-axis alone because you only need a left and right button.

Step 2: Programming for two buttons

  • Save StopOrDrive as the LeftOrRight project.
  • Remember, if you need help opening, naming, or saving projects, watch the Tutorials in VEXcode V5.

Project name dialog box in VEXcode V5 Toolbar reads Left Or Right. Slot 3 is selected to the left and the Toolbar reads Saved to the right.

  • Build the project below. It will have the Clawbot turn left or right when the screen is pressed, depending on the side it is pressed on.

A VEXcode V5 project begins with a when started block with a forever block attached, Inside the forever loop are nested if then else blocks. The If branch of the first if then else block reads If screen pressed. The if then else block nested inside the If branch reads If screen x position less than 240 then turn left, and wait until screen not pressed; else turn right and wait until screen not pressed. The outer else branch contains a drive forward blocks.

The Left or Right project is broken down with the functionality of the blocks in the project labeled. The forever and outer if screen pressed branch are labeled Keeps checking if screen is pressed. The inner if branch is labeled when screen is pressed, checks whether on the left or right. The next turn left block is labeled If press was on the left (less than 240), turns left. The wait until block is labeled waits until screen is no longer pressed before continuing. The turn right block is labeled if press was not on left (less than 240), turns right. The next wait until block is labeled waits until screen is no longer pressed before continuing. The outer else branch with the drive forward block is labeled If screen is not pressed, drives forward.

  • Let's review what this project does.

    It keeps checking if the screen is pressed. If the screen isn't pressed it drives forward but if it is, it checks where the screen is pressed.

    If the press was on the left side (less than 240), it turns left. Otherwise, it turns right. We don't need another condition for when the x-value is greater than 240 because if it isn't less than 240 (turn left), it must be greater (turn right). We only have two buttons to worry about.

    The wait until Control blocks after each turn have the project wait until the screen is no longer being pressed before continuing.

Toolbar in VEXcode V5 with a red box around the download button. The icons read, from left to right, Controller, Brain, Download, Run, Stop, and Share.

  • Now that the project is done, download and run it to test how it works.
  • For help, watch the Download and Run a Project tutorial video in VEXcode V5.
  • Take notes in your engineering notebook about how the buttons control the movements of the Clawbot.

When pressing the screen's buttons from behind the Clawbot as it drove forward, you pressed on the right side of the screen to turn left and on the left side of the screen to turn right. That is not a good User Experience. A User Experience is how well a user can interact with a User Interface to control a computer system. There is more information about User Interfaces in the Apply section of this lab.

In this case, we need to improve the User Interface in order to improve the User Experience.

Left or Right VEXcode V5 project. A VEXcode V5 project begins with a when started block with a forever block attached, Inside the forever loop are nested if then else blocks. The If branch of the first if then else block reads If screen pressed. The if then else block nested inside the If branch reads If screen x position less than 240 then turn left, and wait until screen not pressed; else turn right and wait until screen not pressed. The outer else branch contains a drive forward blocks.

  • Review the LeftOrRight project and revise it so that when the user presses the buttons from behind the Clawbot, the robot turns right when the user presses the left side of the screen. Or else, the Clawbot turns left.
  • Plan, test, and iterate on this project in your engineering notebook so that the project makes the Clawbot turn toward the side of the screen that the user is pressing from behind the Clawbot.