Bumper Switch Help

Leugue Chamiponships tommorow!!! Can we get an example for a 2 bumper switch autonomous? We don’t know how to start it. MANY thanks in advance.

What do you mean by a 2 bumper switch Autonomous?

What programming environment are you using?

We are using RobotC. Meaning an autonmous with two triggers for to different autonomous tasks, on the same program.

I have a four-bumper switch example program I can give you.

Program and some other info coming up in the next post.

Ok, so the bumper switches were implemented in this fashion:


bool selected = false;
char Selection = ' ';
while(selected == false) {
		if(SensorValue[Red_Middle] == 1) {
			selected = true;
			Selection = 'R'; //Red_Middle
		}
		else if(SensorValue[Red_Outer] == 1) {
			selected = true;
			Selection = 'r'; //Red_Outer
		}
		else if(SensorValue[Blue_Middle] == 1) {
			selected = true;
			Selection = 'B'; //Blue_Middle
		}
		else if(SensorValue[Blue_Outer] == 1) {
		selected = true;
		Selection = 'b'; //Blue_Outer
		}
		else {
			selected = false;
		}

	}

I then used a switch statement that read the value of the char “Selection” variable. It then executed the code designed for the autonomous specified by the “Selection” variable.

Be aware that the bumper switches return a value of 1 when pressed and a value of 0 when they are not pressed. The bumper switches are plugged into any one of the twelve digital ports.

Hope this helps!
-Programmer for 46A

Ok, could you include where you name the indvidual tasks; ie. “r”, for example?

I just turned off my computer and am on my ohone, so I cannot. However, here is robotc’s documentation on a switch statemen (which is what i used)t:
http://www.robotc.net/wiki/Using_switch_statements

If that doesn’t help, search on Google for tutorials on switch statements in C.

Thanks for the help. We’ll try to work with what we got.

Anyone else know how to name programs, per the example that was given above.

You mean how to select programs? Well I showed you my method, but just in case you didn’t understand what I was talking about:

Let me explain in further detail what a switch statement is. A switch statement is a control structure in a program that reads the value of a variable and, depending on the value of that variable, executes the block of code specified to execute when the variable is a certain value.

For example:


switch(Selection) {
	case 'R':
            //Do stuff
            break;
        case 'B':
           //Do stuff
           break;
}

The code in case ‘R’ will run if the Selection variable equals R, and the code in case ‘B’ will run if the Selection variable equals B. The names of cases are always what the possible values of the variable could be.

The switch statement is explained in more detail here:
http://www.dreamincode.net/forums/topic/220356-control-structures-loops-ifs-and-switch/

It’s in C++, but the switch statements for both programming languages are the exact same. And it’s covered at the bottom of the tutorial.

Also, I recommend reading up on the different variable types that exist in C:
[C - Data Types

You can also look into using the lcd screen, which you seem to have attempted before. Why did you decide not to use the lcd?

Good luck!](C - Data Types)