Drive With Arrows: Use Console to drive your robot.

***** DRIVE WITH ARROWS by Azi Crawford 2011:07:06:09:55:10
***** This program is to control your robot with the virtual buttons
*****  While the up arrow is touched - the robot with go forward at half power
*****  While the down arrow is touched -the robot will go backwards at 1/2 power
*****  While the right arrow is touched - the robot will spin clockwise
*****  While the left arrow is touched - the robot will spin counter-clockwise
/* Libraries used in Botball are automatically included, but lists any 
  additional includes below */

/*Function prototypes below*/
void spin_right();
void spin_left();
void go_forward();
void go_backward();

int main()
	/*Now that I have declared functions that will tell the robot what to do
	** I'll need a way of telling the robot to run them when and *only* when
	** the buttons are pressed. Ideally, it is best to write this out on 
	** paper first - this is called "paper-coding," for this exercise - 
	** I'll be writing out my process in the comments*/

	printf("Use the arrow keys to control the robot.\n");
	printf("Up arrow moves robot forward.\n");
	printf("Down arrow moves the robot backward. \n");
	printf("Right arrow spins the robot clockwise. \n");
	printf("Left arrow spins the robot counter-clockwise.\n");
	printf("Press the black button to end program. \n");

	while(!black_button()) //keeps program going until black button is pressed
	     // if no buttons are pressed - there should be no movement -> ao()
	        if (up_button()) /* an if statement will call the appropriate
                                 function when the button is pushed.*/
	        while(up_button()) /* an empty while loop will keep the robot
                                   spinning while the up arrow is pressed */
		if (down_button()) // same as above, but for moving backwards
		while (down_button())
		if (right_button()) //as above, but for spinning clockwise
		while (right_button())
		if (left_button()) //as above, but spinning counter-clockwise
		while (left_button())
		ao(); // if nothing is touched - nothing should move
} // end of main

/*Function definitions go below.*/
void spin_right()
 void spin_left()
 void go_forward()
 void go_backward()

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s