13.07.2015 Views

Programming - VEX Robotics

Programming - VEX Robotics

Programming - VEX Robotics

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

programmingautonomous programsprogram three: using motors and sensors together, continued5 Your program should now look like this.ConfigBEGINVariablesvoid main (void){6 In the "Function Block" window, under the"Inputs" Heading, find the "Bumper Switch" iconand drag this into the program window betweenthe { and } brackets of the while loop. Set the"Digital Input #" to 6 (where the front bumper switchis plugged in, see page 33 for setup details), and the"Retrieve to" to the variable you created, "bumper".Click OK when you are done.You have now set the variable "bumper" to be updatedwith the current value of the bump sensor each time theloop is run.7If the bump sensor is not pushed in, then you want themotors to continue moving the robot forward. If thebump sensor is pushed in, then you want the robot tostop.ConfigBEGINVariablesvoid main (void){Since we are storing the bumper sensor's pushed/notpushedstate in the "bumper" variable, that is where theprogram must look to see whether it is being pushed. Ifthe sensor is pushed, "bumper" will have a value of 0. If itis not pushed, "bumper" will be equal to 1.We will use an if-else statement to perform this check.8In the "Function Block" window, under the "ProgramFlow" heading, drag the "If" block into the while loopunderneath the "Bumper Switch" icon. In the "If"configuration window, the first block asks you to definethe condition (just like a while loop). First, click the smallarrow next to "Add Variable" and select "Bumper". Then,click the arrow next to "Add Operator" and select the"==" operation. After the "==" sign, you will enter thenumber 1. The “if” condition will now check whetherthe variable "bumper" is equal to 1. Click OK to continue.01/31/05Inventor’s Guide8 • 39

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!