|
THS 2011-2012 |
CProg /
Flow Control: Do This or ThatA program that blindly executes a list of commands may be useful, but without the ability to detect changes in its data or make choices based on the data, the program will remain very limited. In robotics, making choices based on the data is essential: Has the robot bumped into something? Are the batteries low? How close is the robot to the wall? Is the floor below the robot black, white, or blue? These are the types of questions your robot will need to answer and respond to. The most basic C command that you will use to make a choice is the
// If statement with one command
if(condition_is_true)
do_this_command;
// If statement with multiple commands
if(condition_is_true)
{
do_this_command;
do_that_command;
}
The first part of the One of the simplest things you can do with the Create is to detect if one of it's bumpers is pressed. Show how if is used to sense bumper. Then expand to use an else. Then show if-elseif-else for both bumpers. Make note of use of cr8_update() << Data Structure | Home Page | User Input >> Have a Question? Please ask below. |